diff --git a/package.json b/package.json index 55d232a520932..73c007dfa3f22 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "babel-code-frame": "^6.26.0", "babel-core": "^6.0.0", "babel-eslint": "^8.0.0", - "babel-jest": "^22.4.4", + "babel-jest": "^23.0.1", "babel-plugin-check-es2015-constants": "^6.5.0", "babel-plugin-external-helpers": "^6.22.0", "babel-plugin-syntax-trailing-function-commas": "^6.5.0", @@ -69,8 +69,8 @@ "gzip-js": "~0.3.2", "gzip-size": "^3.0.0", "jasmine-check": "^1.0.0-rc.0", - "jest": "^22.4.4", - "jest-diff": "^22.4.3", + "jest": "^23.0.1", + "jest-diff": "^23.0.1", "merge-stream": "^1.0.0", "minimatch": "^3.0.4", "minimist": "^1.2.0", diff --git a/packages/react-dom/src/__tests__/DOMPropertyOperations-test.js b/packages/react-dom/src/__tests__/DOMPropertyOperations-test.js index 08874222d594c..1fba16247e2bd 100644 --- a/packages/react-dom/src/__tests__/DOMPropertyOperations-test.js +++ b/packages/react-dom/src/__tests__/DOMPropertyOperations-test.js @@ -123,7 +123,7 @@ describe('DOMPropertyOperations', () => { spyOnDevAndProd(container.firstChild, 'setAttribute'); ReactDOM.render(, container); ReactDOM.render(, container); - expect(container.firstChild.setAttribute.calls.count()).toBe(2); + expect(container.firstChild.setAttribute).toHaveBeenCalledTimes(2); }); }); diff --git a/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js b/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js index d1fde4af6a4d6..85d6e22dfbc07 100644 --- a/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js @@ -151,17 +151,17 @@ describe('ReactBrowserEventEmitter', () => { it('should invoke a simple handler registered on a node', () => { registerSimpleTestHandler(); ReactTestUtils.Simulate.click(CHILD); - expect(LISTENER.mock.calls.length).toBe(1); + expect(LISTENER).toHaveBeenCalledTimes(1); }); it('should not invoke handlers if ReactBrowserEventEmitter is disabled', () => { registerSimpleTestHandler(); ReactBrowserEventEmitter.setEnabled(false); ReactTestUtils.SimulateNative.click(CHILD); - expect(LISTENER.mock.calls.length).toBe(0); + expect(LISTENER).toHaveBeenCalledTimes(0); ReactBrowserEventEmitter.setEnabled(true); ReactTestUtils.SimulateNative.click(CHILD); - expect(LISTENER.mock.calls.length).toBe(1); + expect(LISTENER).toHaveBeenCalledTimes(1); }); it('should bubble simply', () => { @@ -301,7 +301,7 @@ describe('ReactBrowserEventEmitter', () => { putListener(CHILD, ON_CLICK_KEY, handleChildClick); putListener(PARENT, ON_CLICK_KEY, handleParentClick); ReactTestUtils.Simulate.click(CHILD); - expect(handleParentClick.mock.calls.length).toBe(1); + expect(handleParentClick).toHaveBeenCalledTimes(1); }); it('should not invoke newly inserted handlers while bubbling', () => { @@ -311,7 +311,7 @@ describe('ReactBrowserEventEmitter', () => { }; putListener(CHILD, ON_CLICK_KEY, handleChildClick); ReactTestUtils.Simulate.click(CHILD); - expect(handleParentClick.mock.calls.length).toBe(0); + expect(handleParentClick).toHaveBeenCalledTimes(0); }); it('should have mouse enter simulated by test utils', () => { @@ -325,7 +325,7 @@ describe('ReactBrowserEventEmitter', () => { spyOnDevAndProd(EventTarget.prototype, 'addEventListener'); ReactBrowserEventEmitter.listenTo(ON_CLICK_KEY, document); ReactBrowserEventEmitter.listenTo(ON_CLICK_KEY, document); - expect(EventTarget.prototype.addEventListener.calls.count()).toBe(1); + expect(EventTarget.prototype.addEventListener).toHaveBeenCalledTimes(1); }); it('should work with event plugins without dependencies', () => { diff --git a/packages/react-dom/src/__tests__/ReactComponent-test.js b/packages/react-dom/src/__tests__/ReactComponent-test.js index 9c2d6447ff56b..37f3fc226a3b8 100644 --- a/packages/react-dom/src/__tests__/ReactComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactComponent-test.js @@ -387,11 +387,11 @@ describe('ReactComponent', () => { const callback = jest.fn(); const container = document.createElement('div'); ReactDOM.render(
, container, callback); - expect(callback.mock.calls.length).toBe(1); + expect(callback).toHaveBeenCalledTimes(1); ReactDOM.render(
, container, callback); - expect(callback.mock.calls.length).toBe(2); + expect(callback).toHaveBeenCalledTimes(2); ReactDOM.render(, container, callback); - expect(callback.mock.calls.length).toBe(3); + expect(callback).toHaveBeenCalledTimes(3); }); it('throws usefully when rendering badly-typed elements', () => { diff --git a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js index 0e2986a1f5d34..441545fc0a154 100644 --- a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js @@ -738,28 +738,28 @@ describe('ReactDOMComponent', () => { node.removeAttribute.mockImplementation(nodeRemoveAttribute); ReactDOM.render(
, container); - expect(node.setAttribute.mock.calls.length).toBe(0); - expect(node.removeAttribute.mock.calls.length).toBe(0); + expect(node.setAttribute).toHaveBeenCalledTimes(0); + expect(node.removeAttribute).toHaveBeenCalledTimes(0); ReactDOM.render(
, container); - expect(node.setAttribute.mock.calls.length).toBe(1); - expect(node.removeAttribute.mock.calls.length).toBe(0); + expect(node.setAttribute).toHaveBeenCalledTimes(1); + expect(node.removeAttribute).toHaveBeenCalledTimes(0); ReactDOM.render(
, container); - expect(node.setAttribute.mock.calls.length).toBe(1); - expect(node.removeAttribute.mock.calls.length).toBe(0); + expect(node.setAttribute).toHaveBeenCalledTimes(1); + expect(node.removeAttribute).toHaveBeenCalledTimes(0); ReactDOM.render(
, container); - expect(node.setAttribute.mock.calls.length).toBe(1); - expect(node.removeAttribute.mock.calls.length).toBe(1); + expect(node.setAttribute).toHaveBeenCalledTimes(1); + expect(node.removeAttribute).toHaveBeenCalledTimes(1); ReactDOM.render(
, container); - expect(node.setAttribute.mock.calls.length).toBe(2); - expect(node.removeAttribute.mock.calls.length).toBe(1); + expect(node.setAttribute).toHaveBeenCalledTimes(2); + expect(node.removeAttribute).toHaveBeenCalledTimes(1); ReactDOM.render(
, container); - expect(node.setAttribute.mock.calls.length).toBe(2); - expect(node.removeAttribute.mock.calls.length).toBe(2); + expect(node.setAttribute).toHaveBeenCalledTimes(2); + expect(node.removeAttribute).toHaveBeenCalledTimes(2); }); it('should not incur unnecessary DOM mutations for string properties', () => { @@ -768,7 +768,7 @@ describe('ReactDOMComponent', () => { const node = container.firstChild; - const nodeValueSetter = jest.genMockFn(); + const nodeValueSetter = jest.fn(); const oldSetAttribute = node.setAttribute.bind(node); node.setAttribute = function(key, value) { @@ -777,22 +777,22 @@ describe('ReactDOMComponent', () => { }; ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(1); + expect(nodeValueSetter).toHaveBeenCalledTimes(1); ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(1); + expect(nodeValueSetter).toHaveBeenCalledTimes(1); ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(1); + expect(nodeValueSetter).toHaveBeenCalledTimes(1); ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(1); + expect(nodeValueSetter).toHaveBeenCalledTimes(1); ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(2); + expect(nodeValueSetter).toHaveBeenCalledTimes(2); ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(2); + expect(nodeValueSetter).toHaveBeenCalledTimes(2); }); it('should not incur unnecessary DOM mutations for boolean properties', () => { @@ -812,16 +812,16 @@ describe('ReactDOMComponent', () => { }); ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(0); + expect(nodeValueSetter).toHaveBeenCalledTimes(0); ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(1); + expect(nodeValueSetter).toHaveBeenCalledTimes(1); ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(2); + expect(nodeValueSetter).toHaveBeenCalledTimes(2); ReactDOM.render(
, container); - expect(nodeValueSetter.mock.calls.length).toBe(3); + expect(nodeValueSetter).toHaveBeenCalledTimes(3); }); it('should ignore attribute whitelist for elements with the "is" attribute', () => { @@ -850,9 +850,9 @@ describe('ReactDOMComponent', () => { ReactDOM.render(
, container); ReactDOM.render(
, container); ReactDOM.render(
, container); - expect(setter.mock.calls.length).toBe(0); + expect(setter).toHaveBeenCalledTimes(0); ReactDOM.render(
, container); - expect(setter.mock.calls.length).toBe(1); + expect(setter).toHaveBeenCalledTimes(1); }); it('handles multiple child updates without interference', () => { @@ -984,7 +984,7 @@ describe('ReactDOMComponent', () => { container.getElementsByTagName('source')[0].dispatchEvent(errorEvent); if (__DEV__) { - expect(console.log.calls.count()).toBe(1); + expect(console.log).toHaveBeenCalledTimes(1); expect(console.log.calls.argsFor(0)[0]).toContain('onError called'); } }); @@ -1315,7 +1315,7 @@ describe('ReactDOMComponent', () => { container.getElementsByTagName('image')[0].dispatchEvent(loadEvent); if (__DEV__) { - expect(console.log.calls.count()).toBe(2); + expect(console.log).toHaveBeenCalledTimes(2); expect(console.log.calls.argsFor(0)[0]).toContain('onError called'); expect(console.log.calls.argsFor(1)[0]).toContain('onLoad called'); } diff --git a/packages/react-dom/src/__tests__/ReactDOMEventListener-test.js b/packages/react-dom/src/__tests__/ReactDOMEventListener-test.js index 5c2ff8c5915a6..f34688661c391 100644 --- a/packages/react-dom/src/__tests__/ReactDOMEventListener-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMEventListener-test.js @@ -61,7 +61,7 @@ describe('ReactDOMEventListener', () => { childNode.dispatchEvent(nativeEvent); expect(mouseOut).toBeCalled(); - expect(mouseOut.mock.calls.length).toBe(2); + expect(mouseOut).toHaveBeenCalledTimes(2); expect(mouseOut.mock.calls[0][0]).toEqual(childNode); expect(mouseOut.mock.calls[1][0]).toEqual(parentNode); @@ -97,7 +97,7 @@ describe('ReactDOMEventListener', () => { childNode.dispatchEvent(nativeEvent); expect(mouseOut).toBeCalled(); - expect(mouseOut.mock.calls.length).toBe(3); + expect(mouseOut).toHaveBeenCalledTimes(3); expect(mouseOut.mock.calls[0][0]).toEqual(childNode); expect(mouseOut.mock.calls[1][0]).toEqual(parentNode); expect(mouseOut.mock.calls[2][0]).toEqual(grandParentNode); @@ -169,7 +169,7 @@ describe('ReactDOMEventListener', () => { childNode.dispatchEvent(nativeEvent); // Child and parent should both call from event handlers. - expect(mock.mock.calls.length).toBe(2); + expect(mock).toHaveBeenCalledTimes(2); // The first call schedules a render of '1' into the 'Child'. // However, we're batching so it isn't flushed yet. expect(mock.mock.calls[0][0]).toBe('Child'); @@ -213,7 +213,7 @@ describe('ReactDOMEventListener', () => { instance.getInner().dispatchEvent(nativeEvent); expect(mouseOut).toBeCalled(); - expect(mouseOut.mock.calls.length).toBe(1); + expect(mouseOut).toHaveBeenCalledTimes(1); expect(mouseOut.mock.calls[0][0]).toEqual(instance.getInner()); document.body.removeChild(container); }); diff --git a/packages/react-dom/src/__tests__/ReactDOMIframe-test.js b/packages/react-dom/src/__tests__/ReactDOMIframe-test.js index 074a1d96f2a82..97b07bb0b7722 100644 --- a/packages/react-dom/src/__tests__/ReactDOMIframe-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMIframe-test.js @@ -21,7 +21,7 @@ describe('ReactDOMIframe', () => { }); it('should trigger load events', () => { - const onLoadSpy = jasmine.createSpy(); + const onLoadSpy = jest.fn(); let iframe = React.createElement('iframe', {onLoad: onLoadSpy}); iframe = ReactTestUtils.renderIntoDocument(iframe); diff --git a/packages/react-dom/src/__tests__/ReactDOMInput-test.js b/packages/react-dom/src/__tests__/ReactDOMInput-test.js index f5513557ec3c0..4a3066a073f72 100644 --- a/packages/react-dom/src/__tests__/ReactDOMInput-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMInput-test.js @@ -535,7 +535,7 @@ describe('ReactDOMInput', () => { const node = container.firstChild; let nodeValue = 'a'; - const nodeValueSetter = jest.genMockFn(); + const nodeValueSetter = jest.fn(); Object.defineProperty(node, 'value', { get: function() { return nodeValue; @@ -546,10 +546,10 @@ describe('ReactDOMInput', () => { }); ReactDOM.render( {}} />, container); - expect(nodeValueSetter.mock.calls.length).toBe(0); + expect(nodeValueSetter).toHaveBeenCalledTimes(0); ReactDOM.render( {}} />, container); - expect(nodeValueSetter.mock.calls.length).toBe(1); + expect(nodeValueSetter).toHaveBeenCalledTimes(1); }); it('should not incur unnecessary DOM mutations for numeric type conversion', () => { @@ -558,7 +558,7 @@ describe('ReactDOMInput', () => { const node = container.firstChild; let nodeValue = '0'; - const nodeValueSetter = jest.genMockFn(); + const nodeValueSetter = jest.fn(); Object.defineProperty(node, 'value', { get: function() { return nodeValue; @@ -569,7 +569,7 @@ describe('ReactDOMInput', () => { }); ReactDOM.render( {}} />, container); - expect(nodeValueSetter.mock.calls.length).toBe(0); + expect(nodeValueSetter).toHaveBeenCalledTimes(0); }); it('should not incur unnecessary DOM mutations for the boolean type conversion', () => { @@ -578,7 +578,7 @@ describe('ReactDOMInput', () => { const node = container.firstChild; let nodeValue = 'true'; - const nodeValueSetter = jest.genMockFn(); + const nodeValueSetter = jest.fn(); Object.defineProperty(node, 'value', { get: function() { return nodeValue; @@ -589,7 +589,7 @@ describe('ReactDOMInput', () => { }); ReactDOM.render( {}} />, container); - expect(nodeValueSetter.mock.calls.length).toBe(0); + expect(nodeValueSetter).toHaveBeenCalledTimes(0); }); it('should properly control a value of number `0`', () => { diff --git a/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js b/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js index 9ba7f06674a13..879be14fec3e1 100644 --- a/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js @@ -218,7 +218,7 @@ describe('ReactDOMTextarea', () => { const node = container.firstChild; let nodeValue = 'a'; - const nodeValueSetter = jest.genMockFn(); + const nodeValueSetter = jest.fn(); Object.defineProperty(node, 'value', { get: function() { return nodeValue; @@ -229,10 +229,10 @@ describe('ReactDOMTextarea', () => { }); ReactDOM.render(