Skip to content

Commit

Permalink
Upgrade to Jasmine 2
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov authored and gaearon committed May 25, 2016
1 parent d8a0b9a commit 517ed85
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 76 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"scriptPreprocessor": "scripts/jest/preprocessor.js",
"setupEnvScriptFile": "scripts/jest/environment.js",
"setupTestFrameworkScriptFile": "scripts/jest/test-framework-setup.js",
"testRunner": "jasmine1",
"testFileExtensions": [
"coffee",
"js",
Expand All @@ -99,7 +98,6 @@
"<rootDir>/src",
"node_modules/fbjs"
],
"testRunner": "node_modules/jest-cli/src/testRunners/jasmine/jasmine2.js",
"unmockedModulePathPatterns": [
""
]
Expand Down
12 changes: 6 additions & 6 deletions src/isomorphic/classic/class/__tests__/ReactClass-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ describe('ReactClass-spec', function() {
return <span>{this.props.prop}</span>;
},
});
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toBe(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Component: prop type `prop` is invalid; ' +
'it must be a function, usually from React.PropTypes.'
);
Expand All @@ -87,8 +87,8 @@ describe('ReactClass-spec', function() {
return <span>{this.props.prop}</span>;
},
});
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toBe(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Component: context type `prop` is invalid; ' +
'it must be a function, usually from React.PropTypes.'
);
Expand All @@ -105,8 +105,8 @@ describe('ReactClass-spec', function() {
return <span>{this.props.prop}</span>;
},
});
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toBe(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Component: child context type `prop` is invalid; ' +
'it must be a function, usually from React.PropTypes.'
);
Expand Down
4 changes: 2 additions & 2 deletions src/isomorphic/classic/element/__tests__/ReactElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ describe('ReactElement', function() {
React.createElement('div', {foo: 1});
expect(console.error).not.toHaveBeenCalled();
React.createElement('div', Object.create({foo: 1}));
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'React.createElement(...): Expected props argument to be a plain object. ' +
'Properties defined in its prototype chain will be ignored.'
);
Expand Down
12 changes: 6 additions & 6 deletions src/renderers/dom/client/__tests__/ReactDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ describe('ReactDOM', function() {
});

var myDiv = document.createElement('div');
expect(() => ReactDOM.render(<A />, myDiv, 'no')).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, 'no')).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: string.'
);
expect(() => ReactDOM.render(<A />, myDiv, {})).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, {})).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Object.'
);
expect(() => ReactDOM.render(<A />, myDiv, new Foo())).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, new Foo())).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Foo (keys: a, b).'
);
Expand All @@ -164,15 +164,15 @@ describe('ReactDOM', function() {
var myDiv = document.createElement('div');
ReactDOM.render(<A />, myDiv);

expect(() => ReactDOM.render(<A />, myDiv, 'no')).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, 'no')).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: string.'
);
expect(() => ReactDOM.render(<A />, myDiv, {})).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, {})).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Object.'
);
expect(() => ReactDOM.render(<A />, myDiv, new Foo())).toThrow(
expect(() => ReactDOM.render(<A />, myDiv, new Foo())).toThrowError(
'ReactDOM.render(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: Foo (keys: a, b).'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('SyntheticEvent', function() {
// once for each property accessed
expect(console.error.calls.count()).toBe(3);
// assert the first warning for accessing `type`
expect(console.error.argsFor(0)[0]).toBe(
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: This synthetic event is reused for performance reasons. If ' +
'you\'re seeing this, you\'re accessing the property `type` on a ' +
'released/nullified synthetic event. This is set to null. If you must ' +
Expand All @@ -105,7 +105,7 @@ describe('SyntheticEvent', function() {
syntheticEvent.destructor();
expect(syntheticEvent.type = 'MouseEvent').toBe('MouseEvent');
expect(console.error.calls.count()).toBe(1);
expect(console.error.argsFor(0)[0]).toBe(
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: This synthetic event is reused for performance reasons. If ' +
'you\'re seeing this, you\'re setting the property `type` on a ' +
'released/nullified synthetic event. This is effectively a no-op. If you must ' +
Expand All @@ -120,7 +120,7 @@ describe('SyntheticEvent', function() {
SyntheticEvent.release(syntheticEvent);
syntheticEvent.preventDefault();
expect(console.error.calls.count()).toBe(1);
expect(console.error.argsFor(0)[0]).toBe(
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: This synthetic event is reused for performance reasons. If ' +
'you\'re seeing this, you\'re accessing the method `preventDefault` on a ' +
'released/nullified synthetic event. This is a no-op function. If you must ' +
Expand All @@ -135,7 +135,7 @@ describe('SyntheticEvent', function() {
SyntheticEvent.release(syntheticEvent);
syntheticEvent.stopPropagation();
expect(console.error.calls.count()).toBe(1);
expect(console.error.argsFor(0)[0]).toBe(
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: This synthetic event is reused for performance reasons. If ' +
'you\'re seeing this, you\'re accessing the method `stopPropagation` on a ' +
'released/nullified synthetic event. This is a no-op function. If you must ' +
Expand All @@ -162,7 +162,7 @@ describe('SyntheticEvent', function() {
event.nativeEvent; // eslint-disable-line no-unused-expressions

expect(console.error.calls.count()).toBe(1);
expect(console.error.argsFor(0)[0]).toBe(
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: This synthetic event is reused for performance reasons. If ' +
'you\'re seeing this, you\'re accessing the property `nativeEvent` on a ' +
'released/nullified synthetic event. This is set to null. If you must ' +
Expand All @@ -179,7 +179,7 @@ describe('SyntheticEvent', function() {
expect(syntheticEvent.foo).toBe('bar');
if (typeof Proxy === 'function') {
expect(console.error.calls.count()).toBe(1);
expect(console.error.argsFor(0)[0]).toBe(
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: This synthetic event is reused for performance reasons. If ' +
'you\'re seeing this, you\'re adding a new property in the synthetic ' +
'event object. The property is never released. ' +
Expand Down
6 changes: 3 additions & 3 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ describe('ReactDOMComponent', function() {
it('should support custom elements which extend native elements', function() {
if (ReactDOMFeatureFlags.useCreateElement) {
var container = document.createElement('div');
spyOn(document, 'createElement').andCallThrough();
spyOn(document, 'createElement').and.callThrough();
ReactDOM.render(<div is="custom-div" />, container);
expect(document.createElement).toHaveBeenCalledWith('div', 'custom-div');
} else {
Expand Down Expand Up @@ -1096,7 +1096,7 @@ describe('ReactDOMComponent', function() {

ReactDOM.unmountComponentAtNode(container);

expect(tracker.stopTracking.calls.length).toBe(1);
expect(tracker.stopTracking.calls.count()).toBe(1);
});

it('should clean up input textarea tracking', function() {
Expand All @@ -1108,7 +1108,7 @@ describe('ReactDOMComponent', function() {

ReactDOM.unmountComponentAtNode(container);

expect(tracker.stopTracking.calls.length).toBe(1);
expect(tracker.stopTracking.calls.count()).toBe(1);
});

it('unmounts children before unsetting DOM node info', function() {
Expand Down
30 changes: 15 additions & 15 deletions src/renderers/dom/shared/__tests__/ReactDOMDebugTool-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ describe('ReactDOMDebugTool', function() {

ReactDOMDebugTool.addDevtool(devtool1);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(1);
expect(handler2.calls.length).toBe(0);
expect(handler1.calls.count()).toBe(1);
expect(handler2.calls.count()).toBe(0);

ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(2);
expect(handler2.calls.length).toBe(0);
expect(handler1.calls.count()).toBe(2);
expect(handler2.calls.count()).toBe(0);

ReactDOMDebugTool.addDevtool(devtool2);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(3);
expect(handler2.calls.length).toBe(1);
expect(handler1.calls.count()).toBe(3);
expect(handler2.calls.count()).toBe(1);

ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(2);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(2);

ReactDOMDebugTool.removeDevtool(devtool1);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(3);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(3);

ReactDOMDebugTool.removeDevtool(devtool2);
ReactDOMDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(3);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(3);
});

it('warns once when an error is thrown in devtool', () => {
Expand All @@ -63,13 +63,13 @@ describe('ReactDOMDebugTool', function() {
});

ReactDOMDebugTool.onTestEvent();
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'exception thrown by devtool while handling ' +
'onTestEvent: Error: Hi.'
);

ReactDOMDebugTool.onTestEvent();
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});
});
30 changes: 15 additions & 15 deletions src/renderers/shared/__tests__/ReactDebugTool-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ describe('ReactDebugTool', function() {

ReactDebugTool.addDevtool(devtool1);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(1);
expect(handler2.calls.length).toBe(0);
expect(handler1.calls.count()).toBe(1);
expect(handler2.calls.count()).toBe(0);

ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(2);
expect(handler2.calls.length).toBe(0);
expect(handler1.calls.count()).toBe(2);
expect(handler2.calls.count()).toBe(0);

ReactDebugTool.addDevtool(devtool2);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(3);
expect(handler2.calls.length).toBe(1);
expect(handler1.calls.count()).toBe(3);
expect(handler2.calls.count()).toBe(1);

ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(2);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(2);

ReactDebugTool.removeDevtool(devtool1);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(3);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(3);

ReactDebugTool.removeDevtool(devtool2);
ReactDebugTool.onTestEvent();
expect(handler1.calls.length).toBe(4);
expect(handler2.calls.length).toBe(3);
expect(handler1.calls.count()).toBe(4);
expect(handler2.calls.count()).toBe(3);
});

it('warns once when an error is thrown in devtool', () => {
Expand All @@ -63,14 +63,14 @@ describe('ReactDebugTool', function() {
});

ReactDebugTool.onTestEvent();
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'exception thrown by devtool while handling ' +
'onTestEvent: Error: Hi.'
);

ReactDebugTool.onTestEvent();
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});

it('returns isProfiling state', () => {
Expand Down
12 changes: 6 additions & 6 deletions src/renderers/shared/__tests__/ReactPerf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,28 +389,28 @@ describe('ReactPerf', function() {
var measurements = measure(() => {});
spyOn(console, 'error');
ReactPerf.getMeasurementsSummaryMap(measurements);
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'`ReactPerf.getMeasurementsSummaryMap(...)` is deprecated. Use ' +
'`ReactPerf.getWasted(...)` instead.'
);

ReactPerf.getMeasurementsSummaryMap(measurements);
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});

it('warns once when using printDOM', function() {
var measurements = measure(() => {});
spyOn(console, 'error');
ReactPerf.printDOM(measurements);
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'`ReactPerf.printDOM(...)` is deprecated. Use ' +
'`ReactPerf.printOperations(...)` instead.'
);

ReactPerf.printDOM(measurements);
expect(console.error.calls.length).toBe(1);
expect(console.error.calls.count()).toBe(1);
});

it('returns isRunning state', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,12 @@ describe('ReactCompositeComponent', function() {
return <div />;
},
});
expect(console.error.calls.length).toBe(0);
expect(console.error.calls.count()).toBe(0);
var instance = ReactDOM.render(<Component />, container);
expect(renderPasses).toBe(2);
expect(instance.state.value).toBe(1);
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toBe(
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: setState(...): Cannot call setState() inside getChildContext()'
);
});
Expand Down
Loading

0 comments on commit 517ed85

Please sign in to comment.