Skip to content

Commit

Permalink
Update Jest APIs on fbsource
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D3229435

fb-gh-sync-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
fbshipit-source-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
  • Loading branch information
cpojer authored and Facebook Github Bot 8 committed Apr 28, 2016
1 parent 192ab66 commit d363b1f
Show file tree
Hide file tree
Showing 51 changed files with 208 additions and 217 deletions.
2 changes: 1 addition & 1 deletion Examples/Movies/__tests__/getImageSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
'use strict';

jest.dontMock('../getImageSource');
jest.unmock('../getImageSource');

var getImageSource = require('../getImageSource');

Expand Down
80 changes: 40 additions & 40 deletions Libraries/Animated/src/__tests__/Animated-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'use strict';

jest
.autoMockOff()
.disableAutomock()
.setMock('Text', {})
.setMock('View', {})
.setMock('Image', {})
Expand All @@ -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: {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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();
Expand All @@ -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]);

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

Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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]);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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},
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions Libraries/Animated/src/__tests__/AnimatedNative-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'use strict';

jest
.autoMockOff()
.disableAutomock()
.setMock('Text', {})
.setMock('View', {})
.setMock('Image', {})
Expand All @@ -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();
}
});

Expand Down
2 changes: 1 addition & 1 deletion Libraries/Animated/src/__tests__/Easing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
'use strict';

jest.dontMock('Easing');
jest.unmock('Easing');

var Easing = require('Easing');
describe('Easing', () => {
Expand Down
6 changes: 3 additions & 3 deletions Libraries/Animated/src/__tests__/Interpolation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Animated/src/__tests__/bezier-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */

jest.dontMock('bezier');
jest.unmock('bezier');
var bezier = require('bezier');

var identity = function (x) { return x; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand All @@ -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,
Expand All @@ -52,10 +50,10 @@ var NativeModules = {
},
ModalFullscreenViewManager: {},
AlertManager: {
alertWithArgs: jest.genMockFunction(),
alertWithArgs: jest.fn(),
},
Clipboard: {
setString: jest.genMockFunction(),
setString: jest.fn(),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
'use strict';

jest.dontMock('NavigationLegacyNavigatorRouteStack');
jest.unmock('NavigationLegacyNavigatorRouteStack');

const NavigationLegacyNavigatorRouteStack = require('NavigationLegacyNavigatorRouteStack');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'use strict';

jest
.autoMockOff()
.disableAutomock()
.mock('ErrorUtils');

var NavigationContext = require('NavigationContext');
Expand Down
Loading

0 comments on commit d363b1f

Please sign in to comment.