From d363b1f2e2a50a023284ee3c370cba3b7f068978 Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Wed, 27 Apr 2016 19:15:28 -0700 Subject: [PATCH] Update Jest APIs on fbsource Reviewed By: javache Differential Revision: D3229435 fb-gh-sync-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c fbshipit-source-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c --- .../Movies/__tests__/getImageSource-test.js | 2 +- .../Animated/src/__tests__/Animated-test.js | 80 +++++++++---------- .../src/__tests__/AnimatedNative-test.js | 22 ++--- .../Animated/src/__tests__/Easing-test.js | 2 +- .../src/__tests__/Interpolation-test.js | 6 +- .../Animated/src/__tests__/bezier-test.js | 2 +- .../__mocks__/NativeModules.js | 28 +++---- ...avigationLegacyNavigatorRouteStack-test.js | 2 +- .../__tests__/NavigationContext-test.js | 2 +- .../__tests__/NavigationEvent-test.js | 4 +- .../__tests__/NavigationEventEmitter-test.js | 12 +-- .../__tests__/NavigationRouteStack-test.js | 2 +- .../__tests__/NavigationTreeNode-test.js | 6 +- .../__tests__/resolveAssetSource-test.js | 8 +- .../__tests__/InteractionManager-test.js | 32 ++++---- .../__tests__/InteractionMixin-test.js | 4 +- .../Interaction/__tests__/TaskQueue-test.js | 14 ++-- .../__tests__/parseErrorStack-test.js | 2 +- .../__tests__/NavigationFindReducer-test.js | 2 +- .../__tests__/NavigationScenesReducer-test.js | 2 +- .../__tests__/NavigationStackReducer-test.js | 4 +- .../__tests__/NavigationTabsReducer-test.js | 6 +- .../__tests__/NavigationStateUtils-test.js | 2 +- .../__tests__/XMLHttpRequestBase-test.js | 4 +- .../StyleSheet/__tests__/flattenStyle-test.js | 2 +- .../__tests__/normalizeColor-test.js | 2 +- .../StyleSheet/__tests__/processColor-test.js | 2 +- .../__tests__/setNormalizedColorAlpha-test.js | 4 +- Libraries/Utilities/__mocks__/ErrorUtils.js | 12 +-- Libraries/Utilities/__mocks__/PixelRatio.js | 22 ++--- .../Utilities/__tests__/MatrixMath-test.js | 4 +- .../Utilities/__tests__/MessageQueue-test.js | 4 +- .../Utilities/__tests__/Platform-test.js | 4 +- Libraries/Utilities/__tests__/utf8-test.js | 2 +- .../differ/__tests__/deepDiffer-test.js | 2 +- .../WebSocket/__tests__/WebSocket-test.js | 2 +- .../src/Activity/__tests__/Activity-test.js | 4 +- .../AssetServer/__tests__/AssetServer-test.js | 10 +-- .../src/Bundler/__tests__/Bundle-test.js | 4 +- .../src/Bundler/__tests__/Bundler-test.js | 8 +- .../__tests__/Transformer-test.js | 14 ++-- .../worker/__tests__/constant-folding-test.js | 2 +- .../__tests__/extract-dependencies-test.js | 2 +- .../worker/__tests__/inline-test.js | 2 +- .../worker/__tests__/minify-test.js | 4 +- .../worker/__tests__/worker-test.js | 4 +- .../src/Resolver/__tests__/Resolver-test.js | 30 +++---- .../polyfills/__tests__/Number.es6-test.js | 2 +- .../polyfills/__tests__/Object.es7-test.js | 2 +- .../src/Server/__tests__/Server-test.js | 23 +++--- .../src/lib/__tests__/declareOpts-test.js | 2 +- 51 files changed, 208 insertions(+), 217 deletions(-) diff --git a/Examples/Movies/__tests__/getImageSource-test.js b/Examples/Movies/__tests__/getImageSource-test.js index d4a2e9df1b5176..2061312f020de2 100644 --- a/Examples/Movies/__tests__/getImageSource-test.js +++ b/Examples/Movies/__tests__/getImageSource-test.js @@ -3,7 +3,7 @@ */ 'use strict'; -jest.dontMock('../getImageSource'); +jest.unmock('../getImageSource'); var getImageSource = require('../getImageSource'); diff --git a/Libraries/Animated/src/__tests__/Animated-test.js b/Libraries/Animated/src/__tests__/Animated-test.js index 8f9b5b54398610..8bdafe7905ae6e 100644 --- a/Libraries/Animated/src/__tests__/Animated-test.js +++ b/Libraries/Animated/src/__tests__/Animated-test.js @@ -9,7 +9,7 @@ 'use strict'; jest - .autoMockOff() + .disableAutomock() .setMock('Text', {}) .setMock('View', {}) .setMock('Image', {}) @@ -22,7 +22,7 @@ describe('Animated', () => { it('works end to end', () => { var anim = new Animated.Value(0); - var callback = jest.genMockFunction(); + var callback = jest.fn(); var node = new Animated.__PropsOnlyForTests({ style: { @@ -75,7 +75,7 @@ describe('Animated', () => { it('does not detach on updates', () => { var anim = new Animated.Value(0); - anim.__detach = jest.genMockFunction(); + anim.__detach = jest.fn(); var c = new Animated.View(); c.props = { @@ -101,11 +101,11 @@ describe('Animated', () => { it('stops animation when detached', () => { // jest environment doesn't have cancelAnimationFrame :( if (!window.cancelAnimationFrame) { - window.cancelAnimationFrame = jest.genMockFunction(); + window.cancelAnimationFrame = jest.fn(); } var anim = new Animated.Value(0); - var callback = jest.genMockFunction(); + var callback = jest.fn(); var c = new Animated.View(); c.props = { @@ -125,14 +125,14 @@ describe('Animated', () => { it('triggers callback when spring is at rest', () => { var anim = new Animated.Value(0); - var callback = jest.genMockFunction(); + var callback = jest.fn(); Animated.spring(anim, {toValue: 0, velocity: 0}).start(callback); expect(callback).toBeCalled(); }); it('send toValue when a spring stops', () => { var anim = new Animated.Value(0); - var listener = jest.genMockFunction(); + var listener = jest.fn(); anim.addListener(listener); Animated.spring(anim, {toValue: 15}).start(); jest.runAllTimers(); @@ -148,15 +148,15 @@ describe('Animated', () => { describe('Animated Sequence', () => { it('works with an empty sequence', () => { - var cb = jest.genMockFunction(); + var cb = jest.fn(); Animated.sequence([]).start(cb); expect(cb).toBeCalledWith({finished: true}); }); it('sequences well', () => { - var anim1 = {start: jest.genMockFunction()}; - var anim2 = {start: jest.genMockFunction()}; - var cb = jest.genMockFunction(); + var anim1 = {start: jest.fn()}; + var anim2 = {start: jest.fn()}; + var cb = jest.fn(); var seq = Animated.sequence([anim1, anim2]); @@ -179,9 +179,9 @@ describe('Animated Sequence', () => { }); it('supports interrupting sequence', () => { - var anim1 = {start: jest.genMockFunction()}; - var anim2 = {start: jest.genMockFunction()}; - var cb = jest.genMockFunction(); + var anim1 = {start: jest.fn()}; + var anim2 = {start: jest.fn()}; + var cb = jest.fn(); Animated.sequence([anim1, anim2]).start(cb); @@ -193,9 +193,9 @@ describe('Animated Sequence', () => { }); it('supports stopping sequence', () => { - var anim1 = {start: jest.genMockFunction(), stop: jest.genMockFunction()}; - var anim2 = {start: jest.genMockFunction(), stop: jest.genMockFunction()}; - var cb = jest.genMockFunction(); + var anim1 = {start: jest.fn(), stop: jest.fn()}; + var anim2 = {start: jest.fn(), stop: jest.fn()}; + var cb = jest.fn(); var seq = Animated.sequence([anim1, anim2]); seq.start(cb); @@ -215,14 +215,14 @@ describe('Animated Sequence', () => { describe('Animated Parallel', () => { it('works with an empty parallel', () => { - var cb = jest.genMockFunction(); + var cb = jest.fn(); Animated.parallel([]).start(cb); expect(cb).toBeCalledWith({finished: true}); }); it('works with an empty element in array', () => { - var anim1 = {start: jest.genMockFunction()}; - var cb = jest.genMockFunction(); + var anim1 = {start: jest.fn()}; + var cb = jest.fn(); Animated.parallel([null, anim1]).start(cb); expect(anim1.start).toBeCalled(); @@ -232,9 +232,9 @@ describe('Animated Parallel', () => { }); it('parellelizes well', () => { - var anim1 = {start: jest.genMockFunction()}; - var anim2 = {start: jest.genMockFunction()}; - var cb = jest.genMockFunction(); + var anim1 = {start: jest.fn()}; + var anim2 = {start: jest.fn()}; + var cb = jest.fn(); var par = Animated.parallel([anim1, anim2]); @@ -255,9 +255,9 @@ describe('Animated Parallel', () => { }); it('supports stopping parallel', () => { - var anim1 = {start: jest.genMockFunction(), stop: jest.genMockFunction()}; - var anim2 = {start: jest.genMockFunction(), stop: jest.genMockFunction()}; - var cb = jest.genMockFunction(); + var anim1 = {start: jest.fn(), stop: jest.fn()}; + var anim2 = {start: jest.fn(), stop: jest.fn()}; + var cb = jest.fn(); var seq = Animated.parallel([anim1, anim2]); seq.start(cb); @@ -276,10 +276,10 @@ describe('Animated Parallel', () => { it('does not call stop more than once when stopping', () => { - var anim1 = {start: jest.genMockFunction(), stop: jest.genMockFunction()}; - var anim2 = {start: jest.genMockFunction(), stop: jest.genMockFunction()}; - var anim3 = {start: jest.genMockFunction(), stop: jest.genMockFunction()}; - var cb = jest.genMockFunction(); + var anim1 = {start: jest.fn(), stop: jest.fn()}; + var anim2 = {start: jest.fn(), stop: jest.fn()}; + var anim3 = {start: jest.fn(), stop: jest.fn()}; + var cb = jest.fn(); var seq = Animated.parallel([anim1, anim2, anim3]); seq.start(cb); @@ -306,8 +306,8 @@ describe('Animated Parallel', () => { describe('Animated delays', () => { it('should call anim after delay in sequence', () => { - var anim = {start: jest.genMockFunction(), stop: jest.genMockFunction()}; - var cb = jest.genMockFunction(); + var anim = {start: jest.fn(), stop: jest.fn()}; + var cb = jest.fn(); Animated.sequence([ Animated.delay(1000), anim, @@ -319,7 +319,7 @@ describe('Animated delays', () => { expect(cb).toBeCalledWith({finished: true}); }); it('should run stagger to end', () => { - var cb = jest.genMockFunction(); + var cb = jest.fn(); Animated.stagger(1000, [ Animated.delay(1000), Animated.delay(1000), @@ -341,7 +341,7 @@ describe('Animated Events', () => { }); it('should call listeners', () => { var value = new Animated.Value(0); - var listener = jest.genMockFunction(); + var listener = jest.fn(); var handler = Animated.event( [{foo: value}], {listener}, @@ -366,14 +366,14 @@ describe('Animated Interactions', () => { }); afterEach(()=> { - jest.dontMock('InteractionManager'); + jest.unmock('InteractionManager'); }); it('registers an interaction by default', () => { InteractionManager.createInteractionHandle.mockReturnValue(777); var value = new Animated.Value(0); - var callback = jest.genMockFunction(); + var callback = jest.fn(); Animated.timing(value, { toValue: 100, duration: 100, @@ -387,7 +387,7 @@ describe('Animated Interactions', () => { it('does not register an interaction when specified', () => { var value = new Animated.Value(0); - var callback = jest.genMockFunction(); + var callback = jest.fn(); Animated.timing(value, { toValue: 100, duration: 100, @@ -451,7 +451,7 @@ describe('Animated Vectors', () => { it('should animate vectors', () => { var vec = new Animated.ValueXY(); - var callback = jest.genMockFunction(); + var callback = jest.fn(); var node = new Animated.__PropsOnlyForTests({ style: { @@ -536,7 +536,7 @@ describe('Animated Vectors', () => { describe('Animated Listeners', () => { it('should get updates', () => { var value1 = new Animated.Value(0); - var listener = jest.genMockFunction(); + var listener = jest.fn(); var id = value1.addListener(listener); value1.setValue(42); expect(listener.mock.calls.length).toBe(1); @@ -554,7 +554,7 @@ describe('Animated Listeners', () => { it('should removeAll', () => { var value1 = new Animated.Value(0); - var listener = jest.genMockFunction(); + var listener = jest.fn(); [1,2,3,4].forEach(() => value1.addListener(listener)); value1.setValue(42); expect(listener.mock.calls.length).toBe(4); diff --git a/Libraries/Animated/src/__tests__/AnimatedNative-test.js b/Libraries/Animated/src/__tests__/AnimatedNative-test.js index bd29f92a119c4a..9fff20cb2792e2 100644 --- a/Libraries/Animated/src/__tests__/AnimatedNative-test.js +++ b/Libraries/Animated/src/__tests__/AnimatedNative-test.js @@ -9,7 +9,7 @@ 'use strict'; jest - .autoMockOff() + .disableAutomock() .setMock('Text', {}) .setMock('View', {}) .setMock('Image', {}) @@ -24,19 +24,19 @@ describe('Animated', () => { beforeEach(() => { var nativeAnimatedModule = require('NativeModules').NativeAnimatedModule; - nativeAnimatedModule.createAnimatedNode = jest.genMockFunction(); - nativeAnimatedModule.connectAnimatedNodes = jest.genMockFunction(); - nativeAnimatedModule.disconnectAnimatedNodes = jest.genMockFunction(); - nativeAnimatedModule.startAnimatingNode = jest.genMockFunction(); - nativeAnimatedModule.stopAnimation = jest.genMockFunction(); - nativeAnimatedModule.setAnimatedNodeValue = jest.genMockFunction(); - nativeAnimatedModule.connectAnimatedNodeToView = jest.genMockFunction(); - nativeAnimatedModule.disconnectAnimatedNodeFromView = jest.genMockFunction(); - nativeAnimatedModule.dropAnimatedNode = jest.genMockFunction(); + nativeAnimatedModule.createAnimatedNode = jest.fn(); + nativeAnimatedModule.connectAnimatedNodes = jest.fn(); + nativeAnimatedModule.disconnectAnimatedNodes = jest.fn(); + nativeAnimatedModule.startAnimatingNode = jest.fn(); + nativeAnimatedModule.stopAnimation = jest.fn(); + nativeAnimatedModule.setAnimatedNodeValue = jest.fn(); + nativeAnimatedModule.connectAnimatedNodeToView = jest.fn(); + nativeAnimatedModule.disconnectAnimatedNodeFromView = jest.fn(); + nativeAnimatedModule.dropAnimatedNode = jest.fn(); // jest environment doesn't have cancelAnimationFrame :( if (!window.cancelAnimationFrame) { - window.cancelAnimationFrame = jest.genMockFunction(); + window.cancelAnimationFrame = jest.fn(); } }); diff --git a/Libraries/Animated/src/__tests__/Easing-test.js b/Libraries/Animated/src/__tests__/Easing-test.js index b865250d7ce14f..1647090854fb37 100644 --- a/Libraries/Animated/src/__tests__/Easing-test.js +++ b/Libraries/Animated/src/__tests__/Easing-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.dontMock('Easing'); +jest.unmock('Easing'); var Easing = require('Easing'); describe('Easing', () => { diff --git a/Libraries/Animated/src/__tests__/Interpolation-test.js b/Libraries/Animated/src/__tests__/Interpolation-test.js index 7f54019fd4b5c3..af8677ac2e1760 100644 --- a/Libraries/Animated/src/__tests__/Interpolation-test.js +++ b/Libraries/Animated/src/__tests__/Interpolation-test.js @@ -9,9 +9,9 @@ 'use strict'; jest - .dontMock('Interpolation') - .dontMock('Easing') - .dontMock('normalizeColor'); + .unmock('Interpolation') + .unmock('Easing') + .unmock('normalizeColor'); var Interpolation = require('Interpolation'); var Easing = require('Easing'); diff --git a/Libraries/Animated/src/__tests__/bezier-test.js b/Libraries/Animated/src/__tests__/bezier-test.js index dfbd818250feac..4b38bae78c8a3a 100644 --- a/Libraries/Animated/src/__tests__/bezier-test.js +++ b/Libraries/Animated/src/__tests__/bezier-test.js @@ -1,6 +1,6 @@ /* eslint-disable */ -jest.dontMock('bezier'); +jest.unmock('bezier'); var bezier = require('bezier'); var identity = function (x) { return x; }; diff --git a/Libraries/BatchedBridge/BatchedBridgedModules/__mocks__/NativeModules.js b/Libraries/BatchedBridge/BatchedBridgedModules/__mocks__/NativeModules.js index 164508ddd03821..9db8b57d2fb78d 100644 --- a/Libraries/BatchedBridge/BatchedBridgedModules/__mocks__/NativeModules.js +++ b/Libraries/BatchedBridge/BatchedBridgedModules/__mocks__/NativeModules.js @@ -10,21 +10,19 @@ var NativeModules = { }), }, Timing: { - createTimer: jest.genMockFunction(), - deleteTimer: jest.genMockFunction(), + createTimer: jest.fn(), + deleteTimer: jest.fn(), }, GraphPhotoUpload: { - upload: jest.genMockFunction(), + upload: jest.fn(), }, FacebookSDK: { - login: jest.genMockFunction(), - logout: jest.genMockFunction(), - queryGraphPath: jest.genMockFunction().mockImpl( - (path, method, params, callback) => callback() - ), + login: jest.fn(), + logout: jest.fn(), + queryGraphPath: jest.fn((path, method, params, callback) => callback()), }, DataManager: { - queryData: jest.genMockFunction(), + queryData: jest.fn(), }, UIManager: { customBubblingEventTypes: {}, @@ -38,10 +36,10 @@ var NativeModules = { }, }, AsyncLocalStorage: { - getItem: jest.genMockFunction(), - setItem: jest.genMockFunction(), - removeItem: jest.genMockFunction(), - clear: jest.genMockFunction(), + getItem: jest.fn(), + setItem: jest.fn(), + removeItem: jest.fn(), + clear: jest.fn(), }, SourceCode: { scriptURL: null, @@ -52,10 +50,10 @@ var NativeModules = { }, ModalFullscreenViewManager: {}, AlertManager: { - alertWithArgs: jest.genMockFunction(), + alertWithArgs: jest.fn(), }, Clipboard: { - setString: jest.genMockFunction(), + setString: jest.fn(), }, }; diff --git a/Libraries/CustomComponents/NavigationExperimental/__tests__/NavigationLegacyNavigatorRouteStack-test.js b/Libraries/CustomComponents/NavigationExperimental/__tests__/NavigationLegacyNavigatorRouteStack-test.js index 9063b49dc8f8a4..48586960b72e91 100644 --- a/Libraries/CustomComponents/NavigationExperimental/__tests__/NavigationLegacyNavigatorRouteStack-test.js +++ b/Libraries/CustomComponents/NavigationExperimental/__tests__/NavigationLegacyNavigatorRouteStack-test.js @@ -29,7 +29,7 @@ */ 'use strict'; -jest.dontMock('NavigationLegacyNavigatorRouteStack'); +jest.unmock('NavigationLegacyNavigatorRouteStack'); const NavigationLegacyNavigatorRouteStack = require('NavigationLegacyNavigatorRouteStack'); diff --git a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationContext-test.js b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationContext-test.js index 5d5ea4813e804e..9f867e704356a4 100644 --- a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationContext-test.js +++ b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationContext-test.js @@ -25,7 +25,7 @@ 'use strict'; jest - .autoMockOff() + .disableAutomock() .mock('ErrorUtils'); var NavigationContext = require('NavigationContext'); diff --git a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEvent-test.js b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEvent-test.js index 81fb1695ef130d..9d3811df64c316 100644 --- a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEvent-test.js +++ b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEvent-test.js @@ -26,8 +26,8 @@ 'use strict'; jest - .dontMock('NavigationEvent') - .dontMock('fbjs/lib/invariant'); + .unmock('NavigationEvent') + .unmock('fbjs/lib/invariant'); var NavigationEvent = require('NavigationEvent'); diff --git a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEventEmitter-test.js b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEventEmitter-test.js index 9e9aef47680771..6704b1f0236a4a 100644 --- a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEventEmitter-test.js +++ b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationEventEmitter-test.js @@ -25,12 +25,12 @@ 'use strict'; jest - .dontMock('EmitterSubscription') - .dontMock('EventSubscription') - .dontMock('EventEmitter') - .dontMock('EventSubscriptionVendor') - .dontMock('NavigationEvent') - .dontMock('NavigationEventEmitter'); + .unmock('EmitterSubscription') + .unmock('EventSubscription') + .unmock('EventEmitter') + .unmock('EventSubscriptionVendor') + .unmock('NavigationEvent') + .unmock('NavigationEventEmitter'); var NavigationEventEmitter = require('NavigationEventEmitter'); diff --git a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationRouteStack-test.js b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationRouteStack-test.js index 7807f9e07072ce..a27e5502f68fb3 100644 --- a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationRouteStack-test.js +++ b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationRouteStack-test.js @@ -26,7 +26,7 @@ jest - .autoMockOff() + .disableAutomock() .mock('ErrorUtils'); var NavigationRouteStack = require('NavigationRouteStack'); diff --git a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationTreeNode-test.js b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationTreeNode-test.js index 68de370caf75bf..f76d5e9bdada55 100644 --- a/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationTreeNode-test.js +++ b/Libraries/CustomComponents/Navigator/Navigation/__tests__/NavigationTreeNode-test.js @@ -5,9 +5,9 @@ 'use strict'; jest - .dontMock('NavigationTreeNode') - .dontMock('fbjs/lib/invariant') - .dontMock('immutable'); + .unmock('NavigationTreeNode') + .unmock('fbjs/lib/invariant') + .unmock('immutable'); var NavigationTreeNode = require('NavigationTreeNode'); diff --git a/Libraries/Image/__tests__/resolveAssetSource-test.js b/Libraries/Image/__tests__/resolveAssetSource-test.js index e31d2f16fa86c0..03a953f92c2eb2 100644 --- a/Libraries/Image/__tests__/resolveAssetSource-test.js +++ b/Libraries/Image/__tests__/resolveAssetSource-test.js @@ -9,10 +9,10 @@ 'use strict'; jest - .dontMock('AssetRegistry') - .dontMock('AssetSourceResolver') - .dontMock('../resolveAssetSource') - .dontMock('../../../local-cli/bundle/assetPathUtils'); + .unmock('AssetRegistry') + .unmock('AssetSourceResolver') + .unmock('../resolveAssetSource') + .unmock('../../../local-cli/bundle/assetPathUtils'); var AssetRegistry = require('AssetRegistry'); var Platform = require('Platform'); diff --git a/Libraries/Interaction/__tests__/InteractionManager-test.js b/Libraries/Interaction/__tests__/InteractionManager-test.js index 032acf2555465b..c41b1e0636ddc7 100644 --- a/Libraries/Interaction/__tests__/InteractionManager-test.js +++ b/Libraries/Interaction/__tests__/InteractionManager-test.js @@ -5,7 +5,7 @@ 'use strict'; jest - .autoMockOff() + .disableAutomock() .mock('ErrorUtils') .mock('BatchedBridge'); @@ -22,8 +22,8 @@ describe('InteractionManager', () => { jest.resetModuleRegistry(); InteractionManager = require('InteractionManager'); - interactionStart = jest.genMockFunction(); - interactionComplete = jest.genMockFunction(); + interactionStart = jest.fn(); + interactionComplete = jest.fn(); InteractionManager.addListener( InteractionManager.Events.interactionStart, @@ -84,7 +84,7 @@ describe('InteractionManager', () => { }); it('runs tasks asynchronously when there are interactions', () => { - var task = jest.genMockFunction(); + var task = jest.fn(); InteractionManager.runAfterInteractions(task); expect(task).not.toBeCalled(); @@ -93,7 +93,7 @@ describe('InteractionManager', () => { }); it('runs tasks when interactions complete', () => { - var task = jest.genMockFunction(); + var task = jest.fn(); var handle = InteractionManager.createInteractionHandle(); InteractionManager.runAfterInteractions(task); @@ -106,8 +106,8 @@ describe('InteractionManager', () => { }); it('does not run tasks twice', () => { - var task1 = jest.genMockFunction(); - var task2 = jest.genMockFunction(); + var task1 = jest.fn(); + var task2 = jest.fn(); InteractionManager.runAfterInteractions(task1); jest.runAllTimers(); @@ -118,10 +118,10 @@ describe('InteractionManager', () => { }); it('runs tasks added while processing previous tasks', () => { - var task1 = jest.genMockFunction().mockImplementation(() => { + var task1 = jest.fn(() => { InteractionManager.runAfterInteractions(task2); }); - var task2 = jest.genMockFunction(); + var task2 = jest.fn(); InteractionManager.runAfterInteractions(task1); expect(task2).not.toBeCalled(); @@ -138,7 +138,7 @@ describe('promise tasks', () => { let BatchedBridge; let sequenceId; function createSequenceTask(expectedSequenceId) { - return jest.genMockFunction().mockImplementation(() => { + return jest.fn(() => { expect(++sequenceId).toBe(expectedSequenceId); }); } @@ -151,7 +151,7 @@ describe('promise tasks', () => { it('should run a basic promise task', () => { - const task1 = jest.genMockFunction().mockImplementation(() => { + const task1 = jest.fn(() => { expect(++sequenceId).toBe(1); return new Promise(resolve => resolve()); }); @@ -161,14 +161,14 @@ describe('promise tasks', () => { }); it('should handle nested promises', () => { - const task1 = jest.genMockFunction().mockImplementation(() => { + const task1 = jest.fn(() => { expect(++sequenceId).toBe(1); return new Promise(resolve => { InteractionManager.runAfterInteractions({gen: task2, name: 'gen2'}) .then(resolve); }); }); - const task2 = jest.genMockFunction().mockImplementation(() => { + const task2 = jest.fn(() => { expect(++sequenceId).toBe(2); return new Promise(resolve => resolve()); }); @@ -180,7 +180,7 @@ describe('promise tasks', () => { it('should pause promise tasks during interactions then resume', () => { const task1 = createSequenceTask(1); - const task2 = jest.genMockFunction().mockImplementation(() => { + const task2 = jest.fn(() => { expect(++sequenceId).toBe(2); return new Promise(resolve => { setTimeout(() => { @@ -238,7 +238,7 @@ describe('promise tasks', () => { const bigAsyncTest = () => { const task1 = createSequenceTask(1); - const task2 = jest.genMockFunction().mockImplementation(() => { + const task2 = jest.fn(() => { expect(++sequenceId).toBe(2); return new Promise(resolve => { InteractionManager.runAfterInteractions(task3); @@ -249,7 +249,7 @@ describe('promise tasks', () => { }); }); const task3 = createSequenceTask(3); - const task4 = jest.genMockFunction().mockImplementation(() => { + const task4 = jest.fn(() => { expect(++sequenceId).toBe(4); return new Promise(resolve => { InteractionManager.runAfterInteractions(task5).then(resolve); diff --git a/Libraries/Interaction/__tests__/InteractionMixin-test.js b/Libraries/Interaction/__tests__/InteractionMixin-test.js index 8c53cfec83e3b8..548f1bdf96a420 100644 --- a/Libraries/Interaction/__tests__/InteractionMixin-test.js +++ b/Libraries/Interaction/__tests__/InteractionMixin-test.js @@ -9,7 +9,7 @@ */ 'use strict'; -jest.dontMock('InteractionMixin'); +jest.unmock('InteractionMixin'); describe('InteractionMixin', () => { var InteractionManager; @@ -36,7 +36,7 @@ describe('InteractionMixin', () => { }); it('should schedule tasks', () => { - var task = jest.genMockFunction(); + var task = jest.fn(); component.runAfterInteractions(task); expect(InteractionManager.runAfterInteractions).toBeCalledWith(task); }); diff --git a/Libraries/Interaction/__tests__/TaskQueue-test.js b/Libraries/Interaction/__tests__/TaskQueue-test.js index 9b36783db55229..194b333a59e169 100644 --- a/Libraries/Interaction/__tests__/TaskQueue-test.js +++ b/Libraries/Interaction/__tests__/TaskQueue-test.js @@ -4,7 +4,7 @@ 'use strict'; -jest.dontMock('TaskQueue'); +jest.unmock('TaskQueue'); function expectToBeCalledOnce(fn) { expect(fn.mock.calls.length).toBe(1); @@ -23,13 +23,13 @@ describe('TaskQueue', () => { let onMoreTasks; let sequenceId; function createSequenceTask(expectedSequenceId) { - return jest.genMockFunction().mockImplementation(() => { + return jest.fn(() => { expect(++sequenceId).toBe(expectedSequenceId); }); } beforeEach(() => { jest.resetModuleRegistry(); - onMoreTasks = jest.genMockFunction(); + onMoreTasks = jest.fn(); const TaskQueue = require('TaskQueue'); taskQueue = new TaskQueue({onMoreTasks}); sequenceId = 0; @@ -45,7 +45,7 @@ describe('TaskQueue', () => { }); it('should handle blocking promise task', () => { - const task1 = jest.genMockFunction().mockImplementation(() => { + const task1 = jest.fn(() => { return new Promise(resolve => { setTimeout(() => { expect(++sequenceId).toBe(1); @@ -71,7 +71,7 @@ describe('TaskQueue', () => { }); it('should handle nested simple tasks', () => { - const task1 = jest.genMockFunction().mockImplementation(() => { + const task1 = jest.fn(() => { expect(++sequenceId).toBe(1); taskQueue.enqueue({run: task3, name: 'run3'}); }); @@ -88,7 +88,7 @@ describe('TaskQueue', () => { }); it('should handle nested promises', () => { - const task1 = jest.genMockFunction().mockImplementation(() => { + const task1 = jest.fn(() => { return new Promise(resolve => { setTimeout(() => { expect(++sequenceId).toBe(1); @@ -97,7 +97,7 @@ describe('TaskQueue', () => { }, 1); }); }); - const task2 = jest.genMockFunction().mockImplementation(() => { + const task2 = jest.fn(() => { return new Promise(resolve => { setTimeout(() => { expect(++sequenceId).toBe(2); diff --git a/Libraries/JavaScriptAppEngine/Initialization/__tests__/parseErrorStack-test.js b/Libraries/JavaScriptAppEngine/Initialization/__tests__/parseErrorStack-test.js index 6a0855a2c0fcb9..8c2c24a04436cc 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/__tests__/parseErrorStack-test.js +++ b/Libraries/JavaScriptAppEngine/Initialization/__tests__/parseErrorStack-test.js @@ -9,7 +9,7 @@ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); var parseErrorStack = require('parseErrorStack'); diff --git a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationFindReducer-test.js b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationFindReducer-test.js index 660e1c03ef9464..d57afdfb0bd42e 100644 --- a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationFindReducer-test.js +++ b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationFindReducer-test.js @@ -11,7 +11,7 @@ 'use strict'; jest - .dontMock('NavigationFindReducer'); + .unmock('NavigationFindReducer'); const NavigationFindReducer = require('NavigationFindReducer'); diff --git a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationScenesReducer-test.js b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationScenesReducer-test.js index affd15837166da..9cced5b718ab13 100644 --- a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationScenesReducer-test.js +++ b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationScenesReducer-test.js @@ -9,7 +9,7 @@ */ 'use strict'; -jest.dontMock('NavigationScenesReducer'); +jest.unmock('NavigationScenesReducer'); const NavigationScenesReducer = require('NavigationScenesReducer'); diff --git a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationStackReducer-test.js b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationStackReducer-test.js index 95e3c4316a9b25..840dc0d0d6d188 100644 --- a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationStackReducer-test.js +++ b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationStackReducer-test.js @@ -11,8 +11,8 @@ 'use strict'; jest - .dontMock('NavigationStackReducer') - .dontMock('NavigationStateUtils'); + .unmock('NavigationStackReducer') + .unmock('NavigationStateUtils'); jest.setMock('React', {Component() {}, PropTypes: {}}); diff --git a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationTabsReducer-test.js b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationTabsReducer-test.js index 9228d0c7b9763a..bb91b68fd768af 100644 --- a/Libraries/NavigationExperimental/Reducer/__tests__/NavigationTabsReducer-test.js +++ b/Libraries/NavigationExperimental/Reducer/__tests__/NavigationTabsReducer-test.js @@ -11,9 +11,9 @@ 'use strict'; jest - .dontMock('NavigationTabsReducer') - .dontMock('NavigationFindReducer') - .dontMock('NavigationStateUtils'); + .unmock('NavigationTabsReducer') + .unmock('NavigationFindReducer') + .unmock('NavigationStateUtils'); const NavigationTabsReducer = require('NavigationTabsReducer'); diff --git a/Libraries/NavigationExperimental/__tests__/NavigationStateUtils-test.js b/Libraries/NavigationExperimental/__tests__/NavigationStateUtils-test.js index 5b8cf98b5ba40e..97cd5d220cf481 100644 --- a/Libraries/NavigationExperimental/__tests__/NavigationStateUtils-test.js +++ b/Libraries/NavigationExperimental/__tests__/NavigationStateUtils-test.js @@ -11,7 +11,7 @@ 'use strict'; jest - .dontMock('NavigationStateUtils'); + .unmock('NavigationStateUtils'); var NavigationStateUtils = require('NavigationStateUtils'); diff --git a/Libraries/Network/__tests__/XMLHttpRequestBase-test.js b/Libraries/Network/__tests__/XMLHttpRequestBase-test.js index b134b031b5a641..9e30a996989eec 100644 --- a/Libraries/Network/__tests__/XMLHttpRequestBase-test.js +++ b/Libraries/Network/__tests__/XMLHttpRequestBase-test.js @@ -1,8 +1,8 @@ 'use strict'; jest - .autoMockOff() - .dontMock('XMLHttpRequestBase'); + .disableAutomock() + .unmock('XMLHttpRequestBase'); const XMLHttpRequestBase = require('XMLHttpRequestBase'); diff --git a/Libraries/StyleSheet/__tests__/flattenStyle-test.js b/Libraries/StyleSheet/__tests__/flattenStyle-test.js index 80bac695c048c6..2fb14d130447de 100644 --- a/Libraries/StyleSheet/__tests__/flattenStyle-test.js +++ b/Libraries/StyleSheet/__tests__/flattenStyle-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); var flattenStyle = require('flattenStyle'); diff --git a/Libraries/StyleSheet/__tests__/normalizeColor-test.js b/Libraries/StyleSheet/__tests__/normalizeColor-test.js index fd8d7d14746093..4090e51082e38f 100644 --- a/Libraries/StyleSheet/__tests__/normalizeColor-test.js +++ b/Libraries/StyleSheet/__tests__/normalizeColor-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.dontMock('normalizeColor'); +jest.unmock('normalizeColor'); var normalizeColor = require('normalizeColor'); diff --git a/Libraries/StyleSheet/__tests__/processColor-test.js b/Libraries/StyleSheet/__tests__/processColor-test.js index aaf45d5e23e3a2..38b282289aabf7 100644 --- a/Libraries/StyleSheet/__tests__/processColor-test.js +++ b/Libraries/StyleSheet/__tests__/processColor-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); var processColor = require('processColor'); diff --git a/Libraries/StyleSheet/__tests__/setNormalizedColorAlpha-test.js b/Libraries/StyleSheet/__tests__/setNormalizedColorAlpha-test.js index 598652dbba7b35..6a29df07abe9ce 100644 --- a/Libraries/StyleSheet/__tests__/setNormalizedColorAlpha-test.js +++ b/Libraries/StyleSheet/__tests__/setNormalizedColorAlpha-test.js @@ -8,8 +8,8 @@ */ 'use strict'; -jest.dontMock('setNormalizedColorAlpha'); -jest.dontMock('normalizeColor'); +jest.unmock('setNormalizedColorAlpha'); +jest.unmock('normalizeColor'); var setNormalizedColorAlpha = require('setNormalizedColorAlpha'); var normalizeColor = require('normalizeColor'); diff --git a/Libraries/Utilities/__mocks__/ErrorUtils.js b/Libraries/Utilities/__mocks__/ErrorUtils.js index 832d27e6007254..dc4319e1fbd9b6 100644 --- a/Libraries/Utilities/__mocks__/ErrorUtils.js +++ b/Libraries/Utilities/__mocks__/ErrorUtils.js @@ -13,12 +13,12 @@ function reportError(error) { } var ErrorUtils = { - apply: jest.genMockFunction().mockImplementation(execute), - applyWithGuard: jest.genMockFunction().mockImplementation(execute), - guard: jest.genMockFunction().mockImplementation(callback => callback), - inGuard: jest.genMockFunction().mockReturnValue(true), - reportError: jest.genMockFunction().mockImplementation(reportError), - setGlobalHandler: jest.genMockFunction(), + apply: jest.fn(execute), + applyWithGuard: jest.fn(execute), + guard: jest.fn(callback => callback), + inGuard: jest.fn().mockReturnValue(true), + reportError: jest.fn(reportError), + setGlobalHandler: jest.fn(), }; module.exports = ErrorUtils; diff --git a/Libraries/Utilities/__mocks__/PixelRatio.js b/Libraries/Utilities/__mocks__/PixelRatio.js index 6e16eddf171f8f..36e5bacdf3108a 100644 --- a/Libraries/Utilities/__mocks__/PixelRatio.js +++ b/Libraries/Utilities/__mocks__/PixelRatio.js @@ -5,20 +5,14 @@ 'use strict'; const PixelRatio = { - get: jest.genMockFunction().mockReturnValue(2), - getFontScale: jest.genMockFunction().mockImplementation( - () => PixelRatio.get() - ), - getPixelSizeForLayoutSize: jest.genMockFunction().mockImplementation( - layoutSize => Math.round(layoutSize * PixelRatio.get()) - ), - roundToNearestPixel: jest.genMockFunction().mockImplementation( - layoutSize => { - const ratio = PixelRatio.get(); - return Math.round(layoutSize * ratio) / ratio; - } - ), - startDetecting: jest.genMockFunction(), + get: jest.fn().mockReturnValue(2), + getFontScale: jest.fn(() => PixelRatio.get()), + getPixelSizeForLayoutSize: jest.fn(layoutSize => Math.round(layoutSize * PixelRatio.get())), + roundToNearestPixel: jest.fn(layoutSize => { + const ratio = PixelRatio.get(); + return Math.round(layoutSize * ratio) / ratio; + }), + startDetecting: jest.fn(), }; module.exports = PixelRatio; diff --git a/Libraries/Utilities/__tests__/MatrixMath-test.js b/Libraries/Utilities/__tests__/MatrixMath-test.js index b8c10ac402e2d7..949509c543d2ea 100644 --- a/Libraries/Utilities/__tests__/MatrixMath-test.js +++ b/Libraries/Utilities/__tests__/MatrixMath-test.js @@ -8,8 +8,8 @@ */ 'use strict'; -jest.dontMock('MatrixMath'); -jest.dontMock('fbjs/lib/invariant'); +jest.unmock('MatrixMath'); +jest.unmock('fbjs/lib/invariant'); var MatrixMath = require('MatrixMath'); diff --git a/Libraries/Utilities/__tests__/MessageQueue-test.js b/Libraries/Utilities/__tests__/MessageQueue-test.js index 14c50e746d7d96..bc7005d902092c 100644 --- a/Libraries/Utilities/__tests__/MessageQueue-test.js +++ b/Libraries/Utilities/__tests__/MessageQueue-test.js @@ -8,8 +8,8 @@ */ 'use strict'; -jest.dontMock('MessageQueue') - .dontMock('fbjs/lib/keyMirror'); +jest.unmock('MessageQueue') + .unmock('fbjs/lib/keyMirror'); var MessageQueue = require('MessageQueue'); let MODULE_IDS = 0; diff --git a/Libraries/Utilities/__tests__/Platform-test.js b/Libraries/Utilities/__tests__/Platform-test.js index e22fd0733b35b9..625ca3f0323617 100644 --- a/Libraries/Utilities/__tests__/Platform-test.js +++ b/Libraries/Utilities/__tests__/Platform-test.js @@ -8,8 +8,8 @@ */ 'use strict'; -jest.dontMock('../Platform.ios'); -jest.dontMock('../Platform.android'); +jest.unmock('../Platform.ios'); +jest.unmock('../Platform.android'); var PlatformIOS = require('../Platform.ios'); var PlatformAndroid = require('../Platform.android'); diff --git a/Libraries/Utilities/__tests__/utf8-test.js b/Libraries/Utilities/__tests__/utf8-test.js index dd5553706b8efe..51dd50aaae1622 100644 --- a/Libraries/Utilities/__tests__/utf8-test.js +++ b/Libraries/Utilities/__tests__/utf8-test.js @@ -9,7 +9,7 @@ 'use strict'; - jest.autoMockOff(); + jest.disableAutomock(); const {encode} = require('../utf8'); diff --git a/Libraries/Utilities/differ/__tests__/deepDiffer-test.js b/Libraries/Utilities/differ/__tests__/deepDiffer-test.js index 745b83ab093053..c1cc81c886fb1a 100644 --- a/Libraries/Utilities/differ/__tests__/deepDiffer-test.js +++ b/Libraries/Utilities/differ/__tests__/deepDiffer-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.dontMock('deepDiffer'); +jest.unmock('deepDiffer'); var deepDiffer = require('deepDiffer'); describe('deepDiffer', function() { diff --git a/Libraries/WebSocket/__tests__/WebSocket-test.js b/Libraries/WebSocket/__tests__/WebSocket-test.js index baf73597c79c9b..cb9b1541514cc8 100644 --- a/Libraries/WebSocket/__tests__/WebSocket-test.js +++ b/Libraries/WebSocket/__tests__/WebSocket-test.js @@ -3,7 +3,7 @@ */ 'use strict'; -jest.dontMock('WebSocket'); +jest.unmock('WebSocket'); jest.setMock('NativeModules', { WebSocketModule: { connect: () => {} diff --git a/packager/react-packager/src/Activity/__tests__/Activity-test.js b/packager/react-packager/src/Activity/__tests__/Activity-test.js index 0375ee6ff9384c..6c219c223ac7a2 100644 --- a/packager/react-packager/src/Activity/__tests__/Activity-test.js +++ b/packager/react-packager/src/Activity/__tests__/Activity-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); var Activity = require('../'); @@ -16,7 +16,7 @@ describe('Activity', () => { const origConsoleLog = console.log; beforeEach(() => { - console.log = jest.genMockFn(); + console.log = jest.fn(); jest.runOnlyPendingTimers(); }); diff --git a/packager/react-packager/src/AssetServer/__tests__/AssetServer-test.js b/packager/react-packager/src/AssetServer/__tests__/AssetServer-test.js index bf96ae8c800e91..7f59253ca44404 100644 --- a/packager/react-packager/src/AssetServer/__tests__/AssetServer-test.js +++ b/packager/react-packager/src/AssetServer/__tests__/AssetServer-test.js @@ -9,7 +9,7 @@ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); jest .mock('crypto') @@ -199,8 +199,8 @@ describe('AssetServer', () => { describe('assetServer.getAssetData', () => { pit('should get assetData', () => { const hash = { - update: jest.genMockFn(), - digest: jest.genMockFn(), + update: jest.fn(), + digest: jest.fn(), }; hash.digest.mockImpl(() => 'wow such hash'); @@ -241,8 +241,8 @@ describe('AssetServer', () => { pit('should get assetData for non-png images', () => { const hash = { - update: jest.genMockFn(), - digest: jest.genMockFn(), + update: jest.fn(), + digest: jest.fn(), }; hash.digest.mockImpl(() => 'wow such hash'); diff --git a/packager/react-packager/src/Bundler/__tests__/Bundle-test.js b/packager/react-packager/src/Bundler/__tests__/Bundle-test.js index c560d25b0fd5e7..1f6f68ffbf34de 100644 --- a/packager/react-packager/src/Bundler/__tests__/Bundle-test.js +++ b/packager/react-packager/src/Bundler/__tests__/Bundle-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); const Bundle = require('../Bundle'); const ModuleTransport = require('../../lib/ModuleTransport'); @@ -21,7 +21,7 @@ describe('Bundle', () => { beforeEach(() => { bundle = new Bundle({sourceMapUrl: 'test_url'}); - bundle.getSourceMap = jest.genMockFn().mockImpl(() => { + bundle.getSourceMap = jest.fn(() => { return 'test-source-map'; }); }); diff --git a/packager/react-packager/src/Bundler/__tests__/Bundler-test.js b/packager/react-packager/src/Bundler/__tests__/Bundler-test.js index ac5cc0bd995131..f3d5c9520706d1 100644 --- a/packager/react-packager/src/Bundler/__tests__/Bundler-test.js +++ b/packager/react-packager/src/Bundler/__tests__/Bundler-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); jest .setMock('worker-farm', () => () => undefined) @@ -68,8 +68,8 @@ describe('Bundler', function() { var projectRoots; beforeEach(function() { - getDependencies = jest.genMockFn(); - getModuleSystemDependencies = jest.genMockFn(); + getDependencies = jest.fn(); + getModuleSystemDependencies = jest.fn(); projectRoots = ['/root']; Resolver.mockImpl(function() { @@ -90,7 +90,7 @@ describe('Bundler', function() { }); assetServer = { - getAssetData: jest.genMockFn(), + getAssetData: jest.fn(), }; bundler = new Bundler({ diff --git a/packager/react-packager/src/JSTransformer/__tests__/Transformer-test.js b/packager/react-packager/src/JSTransformer/__tests__/Transformer-test.js index dc93a872f370ae..a495e565b6f556 100644 --- a/packager/react-packager/src/JSTransformer/__tests__/Transformer-test.js +++ b/packager/react-packager/src/JSTransformer/__tests__/Transformer-test.js @@ -9,12 +9,12 @@ 'use strict'; jest - .dontMock('../../lib/ModuleTransport') - .dontMock('../'); + .unmock('../../lib/ModuleTransport') + .unmock('../'); -const fs = {writeFileSync: jest.genMockFn()}; +const fs = {writeFileSync: jest.fn()}; const temp = {path: () => '/arbitrary/path'}; -const workerFarm = jest.genMockFn(); +const workerFarm = jest.fn(); jest.setMock('fs', fs); jest.setMock('temp', temp); jest.setMock('worker-farm', workerFarm); @@ -29,15 +29,15 @@ describe('Transformer', function() { const transformModulePath = __filename; beforeEach(function() { - Cache = jest.genMockFn(); - Cache.prototype.get = jest.genMockFn().mockImpl((a, b, c) => c()); + Cache = jest.fn(); + Cache.prototype.get = jest.fn((a, b, c) => c()); fs.writeFileSync.mockClear(); options = {transformModulePath}; workerFarm.mockClear(); workerFarm.mockImpl((opts, path, methods) => { const api = workers = {}; - methods.forEach(method => api[method] = jest.genMockFn()); + methods.forEach(method => api[method] = jest.fn()); return api; }); }); diff --git a/packager/react-packager/src/JSTransformer/worker/__tests__/constant-folding-test.js b/packager/react-packager/src/JSTransformer/worker/__tests__/constant-folding-test.js index 64ad751fe0448d..c717e6d0cef8ca 100644 --- a/packager/react-packager/src/JSTransformer/worker/__tests__/constant-folding-test.js +++ b/packager/react-packager/src/JSTransformer/worker/__tests__/constant-folding-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); const babel = require('babel-core'); const constantFolding = require('../constant-folding'); diff --git a/packager/react-packager/src/JSTransformer/worker/__tests__/extract-dependencies-test.js b/packager/react-packager/src/JSTransformer/worker/__tests__/extract-dependencies-test.js index fba330eeccc7a8..1d78e73a76aae3 100644 --- a/packager/react-packager/src/JSTransformer/worker/__tests__/extract-dependencies-test.js +++ b/packager/react-packager/src/JSTransformer/worker/__tests__/extract-dependencies-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); const extractDependencies = require('../extract-dependencies'); diff --git a/packager/react-packager/src/JSTransformer/worker/__tests__/inline-test.js b/packager/react-packager/src/JSTransformer/worker/__tests__/inline-test.js index 53fe1ed8f3623e..f4d11b53d8a0be 100644 --- a/packager/react-packager/src/JSTransformer/worker/__tests__/inline-test.js +++ b/packager/react-packager/src/JSTransformer/worker/__tests__/inline-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); const inline = require('../inline'); const {transform, transformFromAst} = require('babel-core'); diff --git a/packager/react-packager/src/JSTransformer/worker/__tests__/minify-test.js b/packager/react-packager/src/JSTransformer/worker/__tests__/minify-test.js index 184a4aef584ef9..8eff672e8ddee1 100644 --- a/packager/react-packager/src/JSTransformer/worker/__tests__/minify-test.js +++ b/packager/react-packager/src/JSTransformer/worker/__tests__/minify-test.js @@ -8,10 +8,10 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); const uglify = { - minify: jest.genMockFunction().mockImplementation(code => { + minify: jest.fn(code => { return { code: code.replace(/(^|\W)\s+/g, '$1'), map: {}, diff --git a/packager/react-packager/src/JSTransformer/worker/__tests__/worker-test.js b/packager/react-packager/src/JSTransformer/worker/__tests__/worker-test.js index b66dabe2abcecd..4b6ca5a1d97392 100644 --- a/packager/react-packager/src/JSTransformer/worker/__tests__/worker-test.js +++ b/packager/react-packager/src/JSTransformer/worker/__tests__/worker-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); jest.mock('../constant-folding'); jest.mock('../extract-dependencies'); jest.mock('../inline'); @@ -22,7 +22,7 @@ describe('code transformation worker:', () => { beforeEach(() => { extractDependencies = require('../extract-dependencies').mockReturnValue({}); - transform = jest.genMockFunction(); + transform = jest.fn(); }); it('calls the transform with file name, source code, and transform options', function() { diff --git a/packager/react-packager/src/Resolver/__tests__/Resolver-test.js b/packager/react-packager/src/Resolver/__tests__/Resolver-test.js index f53c69126e3e69..0f53e2a0e25fca 100644 --- a/packager/react-packager/src/Resolver/__tests__/Resolver-test.js +++ b/packager/react-packager/src/Resolver/__tests__/Resolver-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.dontMock('../'); +jest.unmock('../'); jest.mock('path'); const Promise = require('promise'); @@ -16,7 +16,7 @@ const Resolver = require('../'); const path = require('path'); -let DependencyGraph = jest.genMockFn(); +let DependencyGraph = jest.fn(); jest.setMock('node-haste', DependencyGraph); let Module; let Polyfill; @@ -24,26 +24,26 @@ let Polyfill; describe('Resolver', function() { beforeEach(function() { DependencyGraph.mockClear(); - Module = jest.genMockFn().mockImpl(function() { - this.getName = jest.genMockFn(); - this.getDependencies = jest.genMockFn(); - this.isPolyfill = jest.genMockFn().mockReturnValue(false); - this.isJSON = jest.genMockFn().mockReturnValue(false); + Module = jest.fn(function() { + this.getName = jest.fn(); + this.getDependencies = jest.fn(); + this.isPolyfill = jest.fn().mockReturnValue(false); + this.isJSON = jest.fn().mockReturnValue(false); }); - Polyfill = jest.genMockFn().mockImpl(function() { + Polyfill = jest.fn(function() { var polyfill = new Module(); polyfill.isPolyfill.mockReturnValue(true); return polyfill; }); DependencyGraph.replacePatterns = require.requireActual('node-haste/lib/lib/replacePatterns'); - DependencyGraph.prototype.createPolyfill = jest.genMockFn(); - DependencyGraph.prototype.getDependencies = jest.genMockFn(); + DependencyGraph.prototype.createPolyfill = jest.fn(); + DependencyGraph.prototype.getDependencies = jest.fn(); // For the polyfillDeps - path.join = jest.genMockFn().mockImpl((a, b) => b); + path.join = jest.fn((a, b) => b); - DependencyGraph.prototype.load = jest.genMockFn().mockImpl(() => Promise.resolve()); + DependencyGraph.prototype.load = jest.fn(() => Promise.resolve()); }); class ResolutionResponseMock { @@ -81,9 +81,9 @@ describe('Resolver', function() { function createPolyfill(id, dependencies) { var polyfill = new Polyfill({}); - polyfill.getName = jest.genMockFn().mockImpl(() => Promise.resolve(id)); + polyfill.getName = jest.fn(() => Promise.resolve(id)); polyfill.getDependencies = - jest.genMockFn().mockImpl(() => Promise.resolve(dependencies)); + jest.fn(() => Promise.resolve(dependencies)); return polyfill; } @@ -415,7 +415,7 @@ describe('Resolver', function() { let depResolver, minifyCode, module, resolutionResponse, sourceMap; beforeEach(() => { - minifyCode = jest.genMockFn().mockImpl((filename, code, map) => + minifyCode = jest.fn((filename, code, map) => Promise.resolve({code, map})); depResolver = new Resolver({ projectRoot: '/root', diff --git a/packager/react-packager/src/Resolver/polyfills/__tests__/Number.es6-test.js b/packager/react-packager/src/Resolver/polyfills/__tests__/Number.es6-test.js index d91a3aa540222a..c15d38b04fba0d 100644 --- a/packager/react-packager/src/Resolver/polyfills/__tests__/Number.es6-test.js +++ b/packager/react-packager/src/Resolver/polyfills/__tests__/Number.es6-test.js @@ -9,7 +9,7 @@ * @emails oncall+jsinfra */ -jest.autoMockOff(); +jest.disableAutomock(); describe('Number (ES6)', () => { describe('EPSILON', () => { diff --git a/packager/react-packager/src/Resolver/polyfills/__tests__/Object.es7-test.js b/packager/react-packager/src/Resolver/polyfills/__tests__/Object.es7-test.js index ee7782eb781ac4..8d34e2bf27c457 100644 --- a/packager/react-packager/src/Resolver/polyfills/__tests__/Object.es7-test.js +++ b/packager/react-packager/src/Resolver/polyfills/__tests__/Object.es7-test.js @@ -6,7 +6,7 @@ /* eslint-disable fb-www/object-create-only-one-param */ -jest.autoMockOff(); +jest.disableAutomock(); describe('Object (ES7)', () => { beforeEach(() => { diff --git a/packager/react-packager/src/Server/__tests__/Server-test.js b/packager/react-packager/src/Server/__tests__/Server-test.js index b54ef2b82a6f11..a7e702d398c9bf 100644 --- a/packager/react-packager/src/Server/__tests__/Server-test.js +++ b/packager/react-packager/src/Server/__tests__/Server-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); jest.setMock('worker-farm', function() { return () => {}; }) .setMock('timers', { setImmediate: (fn) => setTimeout(fn, 0) }) @@ -54,20 +54,19 @@ describe('processRequest', () => { ) ); - const invalidatorFunc = jest.genMockFunction(); - const watcherFunc = jest.genMockFunction(); + const invalidatorFunc = jest.fn(); + const watcherFunc = jest.fn(); var requestHandler; var triggerFileChange; beforeEach(() => { FileWatcher = require('node-haste').FileWatcher; - Bundler.prototype.bundle = jest.genMockFunction().mockImpl(() => + Bundler.prototype.bundle = jest.fn(() => Promise.resolve({ getSource: () => 'this is the source', getSourceMap: () => 'this is the source map', getEtag: () => 'this is an etag', - }) - ); + })); FileWatcher.prototype.on = function(eventType, callback) { if (eventType !== 'all') { @@ -198,7 +197,7 @@ describe('processRequest', () => { }); it('does not rebuild the bundles that contain a file when that file is changed', () => { - const bundleFunc = jest.genMockFunction(); + const bundleFunc = jest.fn(); bundleFunc .mockReturnValueOnce( Promise.resolve({ @@ -243,7 +242,7 @@ describe('processRequest', () => { }); it('does not rebuild the bundles that contain a file when that file is changed, even when hot loading is enabled', () => { - const bundleFunc = jest.genMockFunction(); + const bundleFunc = jest.fn(); bundleFunc .mockReturnValueOnce( Promise.resolve({ @@ -301,8 +300,8 @@ describe('processRequest', () => { req = new EventEmitter(); req.url = '/onchange'; res = { - writeHead: jest.genMockFn(), - end: jest.genMockFn() + writeHead: jest.fn(), + end: jest.fn() }; }); @@ -326,7 +325,7 @@ describe('processRequest', () => { describe('/assets endpoint', () => { it('should serve simple case', () => { const req = {url: '/assets/imgs/a.png'}; - const res = {end: jest.genMockFn()}; + const res = {end: jest.fn()}; AssetServer.prototype.get.mockImpl(() => Promise.resolve('i am image')); @@ -337,7 +336,7 @@ describe('processRequest', () => { it('should parse the platform option', () => { const req = {url: '/assets/imgs/a.png?platform=ios'}; - const res = {end: jest.genMockFn()}; + const res = {end: jest.fn()}; AssetServer.prototype.get.mockImpl(() => Promise.resolve('i am image')); diff --git a/packager/react-packager/src/lib/__tests__/declareOpts-test.js b/packager/react-packager/src/lib/__tests__/declareOpts-test.js index 0fa1b7c81835a3..c67fa2309d34c5 100644 --- a/packager/react-packager/src/lib/__tests__/declareOpts-test.js +++ b/packager/react-packager/src/lib/__tests__/declareOpts-test.js @@ -8,7 +8,7 @@ */ 'use strict'; -jest.autoMockOff(); +jest.disableAutomock(); var declareOpts = require('../declareOpts');