@samitouri / QOS-React-2 / commits / 8e34514096

Update to Jest 12. Codemod to new Jest APIs.

cpojer committed Apr 26, 2016 at 19:36 UTC 8e34514096e57aed1d6d0b2e9039459744807fb2
27 files changed +75 -75
grunt/tasks/jest.js
+1 -1
@@ -77,7 +77,7 @@ function writeTempConfig(callback) {
77 function run(done, configPath) {
78 grunt.log.writeln('running jest (this may take a while)');
79
80 - var args = ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest')];
80 + var args = ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest'), '--runInBand'];
81 if (configPath) {
82 args.push('--config', configPath);
83 }
package.json
+1 -1
@@ -48,7 +48,7 @@
48 "gulp-babel": "^6.0.0",
49 "gulp-flatten": "^0.2.0",
50 "gzip-js": "~0.3.2",
51 - "jest-cli": "^0.9.0",
51 + "jest-cli": "^12.0.2",
52 "loose-envify": "^1.1.0",
53 "object-assign": "^4.0.1",
54 "platform": "^1.1.0",
src/core/__tests__/ReactErrorBoundaries-test.js
+2 -2
@@ -50,7 +50,7 @@ describe('ReactErrorBoundaries', function() {
50
51 var EventPluginHub = require('EventPluginHub');
52 var container = document.createElement('div');
53 - EventPluginHub.putListener = jest.genMockFn();
53 + EventPluginHub.putListener = jest.fn();
54 ReactDOM.render(<Boundary />, container);
55 expect(EventPluginHub.putListener).not.toBeCalled();
56 });
@@ -120,7 +120,7 @@ describe('ReactErrorBoundaries', function() {
120
121 var EventPluginHub = require('EventPluginHub');
122 var container = document.createElement('div');
123 - EventPluginHub.putListener = jest.genMockFn();
123 + EventPluginHub.putListener = jest.fn();
124 ReactDOM.render(<Boundary />, container);
125 expect(EventPluginHub.putListener).toBeCalled();
126 });
src/isomorphic/classic/class/__tests__/ReactBind-test.js
+4 -4
@@ -20,9 +20,9 @@ describe('autobinding', function() {
20
21 it('Holds reference to instance', function() {
22
23 - var mouseDidEnter = jest.genMockFn();
24 - var mouseDidLeave = jest.genMockFn();
25 - var mouseDidClick = jest.genMockFn();
23 + var mouseDidEnter = jest.fn();
24 + var mouseDidLeave = jest.fn();
25 + var mouseDidClick = jest.fn();
26
27 var TestBindComponent = React.createClass({
28 getInitialState: function() {
@@ -95,7 +95,7 @@ describe('autobinding', function() {
95 });
96
97 it('works with mixins', function() {
98 - var mouseDidClick = jest.genMockFn();
98 + var mouseDidClick = jest.fn();
99
100 var TestMixin = {
101 onClick: mouseDidClick,
src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js
+5 -5
@@ -20,9 +20,9 @@ describe('autobind optout', function() {
20
21 it('should work with manual binding', function() {
22
23 - var mouseDidEnter = jest.genMockFn();
24 - var mouseDidLeave = jest.genMockFn();
25 - var mouseDidClick = jest.genMockFn();
23 + var mouseDidEnter = jest.fn();
24 + var mouseDidLeave = jest.fn();
25 + var mouseDidClick = jest.fn();
26
27 var TestBindComponent = React.createClass({
28 autobind: false,
@@ -138,7 +138,7 @@ describe('autobind optout', function() {
138 });
139
140 it('works with mixins that have not opted out of autobinding', function() {
141 - var mouseDidClick = jest.genMockFn();
141 + var mouseDidClick = jest.fn();
142
143 var TestMixin = {
144 onClick: mouseDidClick,
@@ -164,7 +164,7 @@ describe('autobind optout', function() {
164 });
165
166 it('works with mixins that have opted out of autobinding', function() {
167 - var mouseDidClick = jest.genMockFn();
167 + var mouseDidClick = jest.fn();
168
169 var TestMixin = {
170 autobind: false,
src/isomorphic/classic/class/__tests__/ReactClass-test.js
+1 -1
@@ -43,7 +43,7 @@ describe('ReactClass-spec', function() {
43 });
44
45 it('should copy prop types onto the Constructor', function() {
46 - var propValidator = jest.genMockFn();
46 + var propValidator = jest.fn();
47 var TestComponent = React.createClass({
48 propTypes: {
49 value: propValidator,
src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js
+5 -5
@@ -25,8 +25,8 @@ describe('ReactClass-mixin', function() {
25 beforeEach(function() {
26 React = require('React');
27 ReactTestUtils = require('ReactTestUtils');
28 - mixinPropValidator = jest.genMockFn();
29 - componentPropValidator = jest.genMockFn();
28 + mixinPropValidator = jest.fn();
29 + componentPropValidator = jest.fn();
30
31 var MixinA = {
32 propTypes: {
@@ -107,7 +107,7 @@ describe('ReactClass-mixin', function() {
107 });
108
109 it('should support merging propTypes and statics', function() {
110 - var listener = jest.genMockFn();
110 + var listener = jest.fn();
111 var instance = <TestComponent listener={listener} />;
112 instance = ReactTestUtils.renderIntoDocument(instance);
113
@@ -122,7 +122,7 @@ describe('ReactClass-mixin', function() {
122 });
123
124 it('should support chaining delegate functions', function() {
125 - var listener = jest.genMockFn();
125 + var listener = jest.fn();
126 var instance = <TestComponent listener={listener} />;
127 instance = ReactTestUtils.renderIntoDocument(instance);
128
@@ -135,7 +135,7 @@ describe('ReactClass-mixin', function() {
135 });
136
137 it('should chain functions regardless of spec property order', function() {
138 - var listener = jest.genMockFn();
138 + var listener = jest.fn();
139 var instance = <TestComponentWithReverseSpec listener={listener} />;
140 instance = ReactTestUtils.renderIntoDocument(instance);
141
src/renderers/dom/client/__tests__/ReactBrowserEventEmitter-test.js
+3 -3
@@ -35,7 +35,7 @@ var recordIDAndReturnFalse = function(id, event) {
35 recordID(id);
36 return false;
37 };
38 -var LISTENER = jest.genMockFn();
38 +var LISTENER = jest.fn();
39 var ON_CLICK_KEY = keyOf({onClick: null});
40 var ON_TOUCH_TAP_KEY = keyOf({onTouchTap: null});
41 var ON_CHANGE_KEY = keyOf({onChange: null});
@@ -284,7 +284,7 @@ describe('ReactBrowserEventEmitter', function() {
284 */
285
286 it('should invoke handlers that were removed while bubbling', function() {
287 - var handleParentClick = jest.genMockFn();
287 + var handleParentClick = jest.fn();
288 var handleChildClick = function(event) {
289 EventPluginHub.deleteAllListeners(getInternal(PARENT));
290 };
@@ -303,7 +303,7 @@ describe('ReactBrowserEventEmitter', function() {
303 });
304
305 it('should not invoke newly inserted handlers while bubbling', function() {
306 - var handleParentClick = jest.genMockFn();
306 + var handleParentClick = jest.fn();
307 var handleChildClick = function(event) {
308 EventPluginHub.putListener(
309 getInternal(PARENT),
src/renderers/dom/client/__tests__/ReactEventListener-test.js
+1 -1
@@ -30,7 +30,7 @@ describe('ReactEventListener', function() {
30 ReactEventListener = require('ReactEventListener');
31 ReactTestUtils = require('ReactTestUtils');
32
33 - handleTopLevel = jest.genMockFn();
33 + handleTopLevel = jest.fn();
34 ReactEventListener._handleTopLevel = handleTopLevel;
35 });
36
src/renderers/dom/client/__tests__/ReactMount-test.js
+2 -2
@@ -87,8 +87,8 @@ describe('ReactMount', function() {
87 it('should unmount and remount if the key changes', function() {
88 var container = document.createElement('container');
89
90 - var mockMount = jest.genMockFn();
91 - var mockUnmount = jest.genMockFn();
90 + var mockMount = jest.fn();
91 + var mockUnmount = jest.fn();
92
93 var Component = React.createClass({
94 componentDidMount: mockMount,
src/renderers/dom/client/eventPlugins/__tests__/SelectEventPlugin-test.js
+1 -1
@@ -66,7 +66,7 @@ describe('SelectEventPlugin', function() {
66 },
67 });
68
69 - var cb = jest.genMockFn();
69 + var cb = jest.fn();
70
71 var rendered = ReactTestUtils.renderIntoDocument(
72 <WithSelect onSelect={cb} />
src/renderers/dom/client/wrappers/__tests__/DisabledInputUtil-test.js
+1 -1
@@ -36,7 +36,7 @@ describe('DisabledInputUtils', function() {
36 return element;
37 }
38
39 - var onClick = jest.genMockFn();
39 + var onClick = jest.fn();
40
41 elements.forEach(function(tagName) {
42
src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js
+9 -9
@@ -245,7 +245,7 @@ describe('ReactDOMInput', function() {
245 });
246
247 it('should support ReactLink', function() {
248 - var link = new ReactLink('yolo', jest.genMockFn());
248 + var link = new ReactLink('yolo', jest.fn());
249 var instance = <input type="text" valueLink={link} />;
250
251 instance = ReactTestUtils.renderIntoDocument(instance);
@@ -262,7 +262,7 @@ describe('ReactDOMInput', function() {
262 });
263
264 it('should warn with value and no onChange handler', function() {
265 - var link = new ReactLink('yolo', jest.genMockFn());
265 + var link = new ReactLink('yolo', jest.fn());
266 ReactTestUtils.renderIntoDocument(<input type="text" valueLink={link} />);
267 expect(console.error.argsForCall.length).toBe(1);
268 expect(console.error.argsForCall[0][0]).toContain(
@@ -270,7 +270,7 @@ describe('ReactDOMInput', function() {
270 );
271
272 ReactTestUtils.renderIntoDocument(
273 - <input type="text" value="zoink" onChange={jest.genMockFn()} />
273 + <input type="text" value="zoink" onChange={jest.fn()} />
274 );
275 expect(console.error.argsForCall.length).toBe(1);
276 ReactTestUtils.renderIntoDocument(<input type="text" value="zoink" />);
@@ -302,7 +302,7 @@ describe('ReactDOMInput', function() {
302
303 it('should throw if both value and valueLink are provided', function() {
304 var node = document.createElement('div');
305 - var link = new ReactLink('yolo', jest.genMockFn());
305 + var link = new ReactLink('yolo', jest.fn());
306 var instance = <input type="text" valueLink={link} />;
307
308 expect(() => ReactDOM.render(instance, node)).not.toThrow();
@@ -322,7 +322,7 @@ describe('ReactDOMInput', function() {
322 });
323
324 it('should support checkedLink', function() {
325 - var link = new ReactLink(true, jest.genMockFn());
325 + var link = new ReactLink(true, jest.fn());
326 var instance = <input type="checkbox" checkedLink={link} />;
327
328 instance = ReactTestUtils.renderIntoDocument(instance);
@@ -340,7 +340,7 @@ describe('ReactDOMInput', function() {
340
341 it('should warn with checked and no onChange handler', function() {
342 var node = document.createElement('div');
343 - var link = new ReactLink(true, jest.genMockFn());
343 + var link = new ReactLink(true, jest.fn());
344 ReactDOM.render(<input type="checkbox" checkedLink={link} />, node);
345 expect(console.error.argsForCall.length).toBe(1);
346 expect(console.error.argsForCall[0][0]).toContain(
@@ -351,7 +351,7 @@ describe('ReactDOMInput', function() {
351 <input
352 type="checkbox"
353 checked="false"
354 - onChange={jest.genMockFn()}
354 + onChange={jest.fn()}
355 />
356 );
357 expect(console.error.argsForCall.length).toBe(1);
@@ -379,7 +379,7 @@ describe('ReactDOMInput', function() {
379
380 it('should throw if both checked and checkedLink are provided', function() {
381 var node = document.createElement('div');
382 - var link = new ReactLink(true, jest.genMockFn());
382 + var link = new ReactLink(true, jest.fn());
383 var instance = <input type="checkbox" checkedLink={link} />;
384
385 expect(() => ReactDOM.render(instance, node)).not.toThrow();
@@ -401,7 +401,7 @@ describe('ReactDOMInput', function() {
401
402 it('should throw if both checkedLink and valueLink are provided', function() {
403 var node = document.createElement('div');
404 - var link = new ReactLink(true, jest.genMockFn());
404 + var link = new ReactLink(true, jest.fn());
405 var instance = <input type="checkbox" checkedLink={link} />;
406
407 expect(() => ReactDOM.render(instance, node)).not.toThrow();
src/renderers/dom/client/wrappers/__tests__/ReactDOMSelect-test.js
+1 -1
@@ -348,7 +348,7 @@ describe('ReactDOMSelect', function() {
348 });
349
350 it('should support ReactLink', function() {
351 - var link = new ReactLink('giraffe', jest.genMockFn());
351 + var link = new ReactLink('giraffe', jest.fn());
352 var stub =
353 <select valueLink={link}>
354 <option value="monkey">A monkey!</option>
src/renderers/dom/client/wrappers/__tests__/ReactDOMTextarea-test.js
+1 -1
@@ -237,7 +237,7 @@ describe('ReactDOMTextarea', function() {
237 });
238
239 it('should support ReactLink', function() {
240 - var link = new ReactLink('yolo', jest.genMockFn());
240 + var link = new ReactLink('yolo', jest.fn());
241 var instance = <textarea valueLink={link} />;
242
243 spyOn(console, 'error');
src/renderers/dom/server/__tests__/ReactServerRendering-test.js
+2 -2
@@ -86,7 +86,7 @@ describe('ReactServerRendering', function() {
86
87 it('should not register event listeners', function() {
88 var EventPluginHub = require('EventPluginHub');
89 - var cb = jest.genMockFn();
89 + var cb = jest.fn();
90
91 ReactServerRendering.renderToString(
92 <span onClick={cb}>hello world</span>
@@ -303,7 +303,7 @@ describe('ReactServerRendering', function() {
303
304 it('should not register event listeners', function() {
305 var EventPluginHub = require('EventPluginHub');
306 - var cb = jest.genMockFn();
306 + var cb = jest.fn();
307
308 ReactServerRendering.renderToString(
309 <span onClick={cb}>hello world</span>
src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js
+1 -1
@@ -259,7 +259,7 @@ describe('DOMPropertyOperations', function() {
259 });
260
261 it('should use mutation method where applicable', function() {
262 - var foobarSetter = jest.genMockFn();
262 + var foobarSetter = jest.fn();
263 // inject foobar DOM property
264 DOMProperty.injection.injectDOMPropertyConfig({
265 Properties: {foobar: null},
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
+9 -9
@@ -450,11 +450,11 @@ describe('ReactDOMComponent', function() {
450
451 var node = container.firstChild;
452 var nodeSetAttribute = node.setAttribute;
453 - node.setAttribute = jest.genMockFn();
453 + node.setAttribute = jest.fn();
454 node.setAttribute.mockImpl(nodeSetAttribute);
455
456 var nodeRemoveAttribute = node.removeAttribute;
457 - node.removeAttribute = jest.genMockFn();
457 + node.removeAttribute = jest.fn();
458 node.removeAttribute.mockImpl(nodeRemoveAttribute);
459
460 ReactDOM.render(<div id="" />, container);
@@ -488,7 +488,7 @@ describe('ReactDOMComponent', function() {
488
489 var node = container.firstChild;
490 var nodeValue = ''; // node.value always returns undefined
491 - var nodeValueSetter = jest.genMockFn();
491 + var nodeValueSetter = jest.fn();
492 Object.defineProperty(node, 'value', {
493 get: function() {
494 return nodeValue;
@@ -519,7 +519,7 @@ describe('ReactDOMComponent', function() {
519
520 var node = container.firstChild;
521 var nodeValue = true;
522 - var nodeValueSetter = jest.genMockFn();
522 + var nodeValueSetter = jest.fn();
523 Object.defineProperty(node, 'checked', {
524 get: function() {
525 return nodeValue;
@@ -552,7 +552,7 @@ describe('ReactDOMComponent', function() {
552 var container = document.createElement('div');
553 var node = ReactDOM.render(<div />, container);
554
555 - var setter = jest.genMockFn();
555 + var setter = jest.fn();
556 node.setAttribute = setter;
557
558 ReactDOM.render(<div dir={null} />, container);
@@ -839,8 +839,8 @@ describe('ReactDOMComponent', function() {
839 it('should execute custom event plugin listening behavior', function() {
840 var SimpleEventPlugin = require('SimpleEventPlugin');
841
842 - SimpleEventPlugin.didPutListener = jest.genMockFn();
843 - SimpleEventPlugin.willDeleteListener = jest.genMockFn();
842 + SimpleEventPlugin.didPutListener = jest.fn();
843 + SimpleEventPlugin.willDeleteListener = jest.fn();
844
845 var container = document.createElement('div');
846 ReactDOM.render(
@@ -858,8 +858,8 @@ describe('ReactDOMComponent', function() {
858 it('should handle null and missing properly with event hooks', function() {
859 var SimpleEventPlugin = require('SimpleEventPlugin');
860
861 - SimpleEventPlugin.didPutListener = jest.genMockFn();
862 - SimpleEventPlugin.willDeleteListener = jest.genMockFn();
861 + SimpleEventPlugin.didPutListener = jest.fn();
862 + SimpleEventPlugin.willDeleteListener = jest.fn();
863 var container = document.createElement('div');
864
865 ReactDOM.render(<div onClick={false} />, container);
src/renderers/native/ReactNative/__mocks__/UIManager.js
+4 -4
@@ -12,10 +12,10 @@
12 // Mock of the Native Hooks
13
14 var RCTUIManager = {
15 - createView: jest.genMockFunction(),
16 - setChildren: jest.genMockFunction(),
17 - manageChildren: jest.genMockFunction(),
18 - updateView: jest.genMockFunction(),
15 + createView: jest.fn(),
16 + setChildren: jest.fn(),
17 + manageChildren: jest.fn(),
18 + updateView: jest.fn(),
19 };
20
21 module.exports = RCTUIManager;
src/renderers/native/ReactNative/__tests__/ReactNativeAttributePayload-test.js
+6 -6
@@ -9,8 +9,8 @@
9 */
10 'use strict';
11
12 -jest.dontMock('ReactNativeAttributePayload');
13 -jest.dontMock('ReactNativePropRegistry');
12 +jest.unmock('ReactNativeAttributePayload');
13 +jest.unmock('ReactNativePropRegistry');
14 // jest.dontMock('deepDiffer');
15 // jest.dontMock('flattenStyle');
16
@@ -62,8 +62,8 @@ describe('ReactNativeAttributePayload', function() {
62 });
63
64 it('should use the diff attribute', () => {
65 - var diffA = jest.genMockFunction().mockImpl((a, b) => true);
66 - var diffB = jest.genMockFunction().mockImpl((a, b) => false);
65 + var diffA = jest.fn((a, b) => true);
66 + var diffB = jest.fn((a, b) => false);
67 expect(diff(
68 {a: [1], b: [3]},
69 {a: [2], b: [4]},
@@ -74,8 +74,8 @@ describe('ReactNativeAttributePayload', function() {
74 });
75
76 it('should not use the diff attribute on addition/removal', () => {
77 - var diffA = jest.genMockFunction();
78 - var diffB = jest.genMockFunction();
77 + var diffA = jest.fn();
78 + var diffB = jest.fn();
79 expect(diff(
80 {a: [1]},
81 {b: [2]},
src/renderers/shared/event/__tests__/EventPluginHub-test.js
+1 -1
@@ -12,7 +12,7 @@
12 'use strict';
13
14 jest
15 - .dontMock('EventPluginHub')
15 + .unmock('EventPluginHub')
16 .mock('isEventSupported');
17
18 describe('EventPluginHub', function() {
src/renderers/shared/reconciler/__tests__/ReactComponent-test.js
+1 -1
@@ -255,7 +255,7 @@ describe('ReactComponent', function() {
255 });
256
257 it('fires the callback after a component is rendered', function() {
258 - var callback = jest.genMockFn();
258 + var callback = jest.fn();
259 var container = document.createElement('div');
260 ReactDOM.render(<div />, container, callback);
261 expect(callback.mock.calls.length).toBe(1);
src/renderers/shared/reconciler/__tests__/ReactCompositeComponentNestedState-test.js
+1 -1
@@ -90,7 +90,7 @@ describe('ReactCompositeComponentNestedState-state', function() {
90 var container = document.createElement('div');
91 document.body.appendChild(container);
92
93 - var logger = jest.genMockFn();
93 + var logger = jest.fn();
94
95 void ReactDOM.render(
96 <ParentComponent logger={logger} />,
src/renderers/shared/reconciler/__tests__/ReactCompositeComponentState-test.js
+1 -1
@@ -130,7 +130,7 @@ describe('ReactCompositeComponent-state', function() {
130 var container = document.createElement('div');
131 document.body.appendChild(container);
132
133 - var stateListener = jest.genMockFn();
133 + var stateListener = jest.fn();
134 var instance = ReactDOM.render(
135 <TestComponent stateListener={stateListener} />,
136 container,
src/renderers/shared/reconciler/__tests__/ReactMultiChild-test.js
+9 -9
@@ -26,9 +26,9 @@ describe('ReactMultiChild', function() {
26 it('should update children when possible', function() {
27 var container = document.createElement('div');
28
29 - var mockMount = jest.genMockFn();
30 - var mockUpdate = jest.genMockFn();
31 - var mockUnmount = jest.genMockFn();
29 + var mockMount = jest.fn();
30 + var mockUpdate = jest.fn();
31 + var mockUnmount = jest.fn();
32
33 var MockComponent = React.createClass({
34 componentDidMount: mockMount,
@@ -59,8 +59,8 @@ describe('ReactMultiChild', function() {
59 it('should replace children with different constructors', function() {
60 var container = document.createElement('div');
61
62 - var mockMount = jest.genMockFn();
63 - var mockUnmount = jest.genMockFn();
62 + var mockMount = jest.fn();
63 + var mockUnmount = jest.fn();
64
65 var MockComponent = React.createClass({
66 componentDidMount: mockMount,
@@ -87,8 +87,8 @@ describe('ReactMultiChild', function() {
87 it('should NOT replace children with different owners', function() {
88 var container = document.createElement('div');
89
90 - var mockMount = jest.genMockFn();
91 - var mockUnmount = jest.genMockFn();
90 + var mockMount = jest.fn();
91 + var mockUnmount = jest.fn();
92
93 var MockComponent = React.createClass({
94 componentDidMount: mockMount,
@@ -124,8 +124,8 @@ describe('ReactMultiChild', function() {
124 it('should replace children with different keys', function() {
125 var container = document.createElement('div');
126
127 - var mockMount = jest.genMockFn();
128 - var mockUnmount = jest.genMockFn();
127 + var mockMount = jest.fn();
128 + var mockUnmount = jest.fn();
129
130 var MockComponent = React.createClass({
131 componentDidMount: mockMount,
src/shared/utils/__tests__/accumulateInto-test.js
+1 -1
@@ -12,7 +12,7 @@
12 'use strict';
13
14 jest
15 - .dontMock('accumulateInto');
15 + .unmock('accumulateInto');
16
17 var accumulateInto;
18
src/test/__tests__/ReactTestUtils-test.js
+1 -1
@@ -89,7 +89,7 @@ describe('ReactTestUtils', function() {
89 });
90
91 it('should have shallow unmounting', function() {
92 - var componentWillUnmount = jest.genMockFn();
92 + var componentWillUnmount = jest.fn();
93
94 var SomeComponent = React.createClass({
95 render: function() {