Update Jest APIs on fbsource

Reviewed By: javache

Differential Revision: D3229435

fb-gh-sync-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
fbshipit-source-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
This commit is contained in:
Christoph Pojer 2016-04-27 19:15:28 -07:00 committed by Facebook Github Bot 8
parent 192ab663b7
commit d363b1f2e2
51 changed files with 208 additions and 217 deletions

View File

@ -3,7 +3,7 @@
*/
'use strict';
jest.dontMock('../getImageSource');
jest.unmock('../getImageSource');
var getImageSource = require('../getImageSource');

View File

@ -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);

View File

@ -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();
}
});

View File

@ -8,7 +8,7 @@
*/
'use strict';
jest.dontMock('Easing');
jest.unmock('Easing');
var Easing = require('Easing');
describe('Easing', () => {

View File

@ -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');

View File

@ -1,6 +1,6 @@
/* eslint-disable */
jest.dontMock('bezier');
jest.unmock('bezier');
var bezier = require('bezier');
var identity = function (x) { return x; };

View File

@ -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(),
},
};

View File

@ -29,7 +29,7 @@
*/
'use strict';
jest.dontMock('NavigationLegacyNavigatorRouteStack');
jest.unmock('NavigationLegacyNavigatorRouteStack');
const NavigationLegacyNavigatorRouteStack = require('NavigationLegacyNavigatorRouteStack');

View File

@ -25,7 +25,7 @@
'use strict';
jest
.autoMockOff()
.disableAutomock()
.mock('ErrorUtils');
var NavigationContext = require('NavigationContext');

View File

@ -26,8 +26,8 @@
'use strict';
jest
.dontMock('NavigationEvent')
.dontMock('fbjs/lib/invariant');
.unmock('NavigationEvent')
.unmock('fbjs/lib/invariant');
var NavigationEvent = require('NavigationEvent');

View File

@ -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');

View File

@ -26,7 +26,7 @@
jest
.autoMockOff()
.disableAutomock()
.mock('ErrorUtils');
var NavigationRouteStack = require('NavigationRouteStack');

View File

@ -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');

View File

@ -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');

View File

@ -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);

View File

@ -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);
});

View File

@ -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);

View File

@ -9,7 +9,7 @@
'use strict';
jest.autoMockOff();
jest.disableAutomock();
var parseErrorStack = require('parseErrorStack');

View File

@ -11,7 +11,7 @@
'use strict';
jest
.dontMock('NavigationFindReducer');
.unmock('NavigationFindReducer');
const NavigationFindReducer = require('NavigationFindReducer');

View File

@ -9,7 +9,7 @@
*/
'use strict';
jest.dontMock('NavigationScenesReducer');
jest.unmock('NavigationScenesReducer');
const NavigationScenesReducer = require('NavigationScenesReducer');

View File

@ -11,8 +11,8 @@
'use strict';
jest
.dontMock('NavigationStackReducer')
.dontMock('NavigationStateUtils');
.unmock('NavigationStackReducer')
.unmock('NavigationStateUtils');
jest.setMock('React', {Component() {}, PropTypes: {}});

View File

@ -11,9 +11,9 @@
'use strict';
jest
.dontMock('NavigationTabsReducer')
.dontMock('NavigationFindReducer')
.dontMock('NavigationStateUtils');
.unmock('NavigationTabsReducer')
.unmock('NavigationFindReducer')
.unmock('NavigationStateUtils');
const NavigationTabsReducer = require('NavigationTabsReducer');

View File

@ -11,7 +11,7 @@
'use strict';
jest
.dontMock('NavigationStateUtils');
.unmock('NavigationStateUtils');
var NavigationStateUtils = require('NavigationStateUtils');

View File

@ -1,8 +1,8 @@
'use strict';
jest
.autoMockOff()
.dontMock('XMLHttpRequestBase');
.disableAutomock()
.unmock('XMLHttpRequestBase');
const XMLHttpRequestBase = require('XMLHttpRequestBase');

View File

@ -8,7 +8,7 @@
*/
'use strict';
jest.autoMockOff();
jest.disableAutomock();
var flattenStyle = require('flattenStyle');

View File

@ -8,7 +8,7 @@
*/
'use strict';
jest.dontMock('normalizeColor');
jest.unmock('normalizeColor');
var normalizeColor = require('normalizeColor');

View File

@ -8,7 +8,7 @@
*/
'use strict';
jest.autoMockOff();
jest.disableAutomock();
var processColor = require('processColor');

View File

@ -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');

View File

@ -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;

View File

@ -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 => {
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.genMockFunction(),
}),
startDetecting: jest.fn(),
};
module.exports = PixelRatio;

View File

@ -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');

View File

@ -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;

View File

@ -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');

View File

@ -9,7 +9,7 @@
'use strict';
jest.autoMockOff();
jest.disableAutomock();
const {encode} = require('../utf8');

View File

@ -8,7 +8,7 @@
*/
'use strict';
jest.dontMock('deepDiffer');
jest.unmock('deepDiffer');
var deepDiffer = require('deepDiffer');
describe('deepDiffer', function() {

View File

@ -3,7 +3,7 @@
*/
'use strict';
jest.dontMock('WebSocket');
jest.unmock('WebSocket');
jest.setMock('NativeModules', {
WebSocketModule: {
connect: () => {}

View File

@ -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();
});

View File

@ -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');

View File

@ -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';
});
});

View File

@ -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({

View File

@ -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;
});
});

View File

@ -8,7 +8,7 @@
*/
'use strict';
jest.autoMockOff();
jest.disableAutomock();
const babel = require('babel-core');
const constantFolding = require('../constant-folding');

View File

@ -8,7 +8,7 @@
*/
'use strict';
jest.autoMockOff();
jest.disableAutomock();
const extractDependencies = require('../extract-dependencies');

View File

@ -8,7 +8,7 @@
*/
'use strict';
jest.autoMockOff();
jest.disableAutomock();
const inline = require('../inline');
const {transform, transformFromAst} = require('babel-core');

View File

@ -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: {},

View File

@ -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() {

View File

@ -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',

View File

@ -9,7 +9,7 @@
* @emails oncall+jsinfra
*/
jest.autoMockOff();
jest.disableAutomock();
describe('Number (ES6)', () => {
describe('EPSILON', () => {

View File

@ -6,7 +6,7 @@
/* eslint-disable fb-www/object-create-only-one-param */
jest.autoMockOff();
jest.disableAutomock();
describe('Object (ES7)', () => {
beforeEach(() => {

View File

@ -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'));

View File

@ -8,7 +8,7 @@
*/
'use strict';
jest.autoMockOff();
jest.disableAutomock();
var declareOpts = require('../declareOpts');