Skip to content

Commit

Permalink
Replace jest.genMockFunction and related with jest.fn
Browse files Browse the repository at this point in the history
Summary:Via Pro-Tip from kassens.

Depends on D3161900.

Reviewed By: josephsavona

Differential Revision: D3162968

fb-gh-sync-id: 3702154abdb729d0cfef4416c7bac68f079f32b6
fbshipit-source-id: 3702154abdb729d0cfef4416c7bac68f079f32b6
  • Loading branch information
wincent authored and Facebook Github Bot 6 committed Apr 12, 2016
1 parent 9c7fabc commit 8547af9
Show file tree
Hide file tree
Showing 61 changed files with 180 additions and 180 deletions.
2 changes: 1 addition & 1 deletion src/container/__mocks__/getRelayQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

const getRelayQueries = require.requireActual('getRelayQueries');

module.exports = jest.genMockFunction().mockImplementation(getRelayQueries);
module.exports = jest.fn(getRelayQueries);
12 changes: 6 additions & 6 deletions src/container/__tests__/RelayContainer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ describe('RelayContainer', function() {
beforeEach(function() {
jest.resetModuleRegistry();

const render = jest.genMockFunction().mockImplementation(function() {
const render = jest.fn(function() {
// Make it easier to expect prop values.
render.mock.calls[render.mock.calls.length - 1].props = this.props;
return <div />;
});
MockComponent = React.createClass({render});
MockContainer = Relay.createContainer(MockComponent, {
fragments: {
foo: jest.genMockFunction().mockImplementation(
foo: jest.fn(
() => Relay.QL`fragment on Node{id,name}`
),
bar: jest.genMockFunction().mockImplementation(
bar: jest.fn(
() => Relay.QL`fragment on Node @relay(plural:true){id,name}`
),
},
Expand Down Expand Up @@ -844,14 +844,14 @@ describe('RelayContainer', function() {
'43': {__dataID__: '43', name: 'Tee'},
'44': {__dataID__: '44', name: 'Toe'},
};
const render = jest.genMockFunction().mockImplementation(() => <div />);
const shouldComponentUpdate = jest.genMockFunction();
const render = jest.fn(() => <div />);
const shouldComponentUpdate = jest.fn();

const MockFastComponent = React.createClass({render, shouldComponentUpdate});

const MockFastContainer = Relay.createContainer(MockFastComponent, {
fragments: {
foo: jest.genMockFunction().mockImplementation(
foo: jest.fn(
() => Relay.QL`fragment on Node{id,name}`
),
},
Expand Down
4 changes: 2 additions & 2 deletions src/container/__tests__/RelayContainer_Component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ describe('RelayContainer', function() {
jest.resetModuleRegistry();

MockComponent = React.createClass({
render: jest.genMockFunction().mockImplementation(() => <div />),
render: jest.fn(() => <div />),
});

mockCreateContainer = component => {
MockContainer = Relay.createContainer(component, {
initialVariables: {site: 'mobile'},
fragments: {
foo: jest.genMockFunction().mockImplementation(
foo: jest.fn(
() => Relay.QL`fragment on Node{id,url(site:$site)}`
),
},
Expand Down
22 changes: 11 additions & 11 deletions src/container/__tests__/RelayContainer_setVariables-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ describe('RelayContainer.setVariables', function() {
jest.resetModuleRegistry();

const fragment = Relay.QL`fragment on Node{url(site:$site)}`;
entityQuery = jest.genMockFunction().mockImplementation(() => fragment);
render = jest.genMockFunction().mockImplementation(() => <div />);
entityQuery = jest.fn(() => fragment);
render = jest.fn(() => <div />);

// Make RQLTransform ignore this call.
MockComponent = React.createClass({render});
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('RelayContainer.setVariables', function() {
},
}];
});
const pluralEntityQuery = jest.genMockFunction().mockImplementation(
const pluralEntityQuery = jest.fn(
() => Relay.QL`
fragment on Node @relay(plural:true) {
url(site: $site)
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('RelayContainer.setVariables', function() {
});

it('updates `variables` after callback when data is ready', () => {
const mockCallback = jest.genMockFunction();
const mockCallback = jest.fn();
mockInstance.setVariables({site: 'www'}, mockCallback);
jest.runAllTimers();

Expand Down Expand Up @@ -297,7 +297,7 @@ describe('RelayContainer.setVariables', function() {

environment.primeCache.mock.requests[0].block();

const mockCallback = jest.genMockFunction();
const mockCallback = jest.fn();
mockInstance.setVariables({site: 'mobile'}, mockCallback);
jest.runAllTimers();

Expand Down Expand Up @@ -349,7 +349,7 @@ describe('RelayContainer.setVariables', function() {
});

it('invokes the callback as many times as ready state changes', () => {
const mockFunction = jest.genMockFunction().mockImplementation(function() {
const mockFunction = jest.fn(function() {
expect(this.constructor).toBe(MockComponent);
});
mockInstance.setVariables({site: 'www'}, mockFunction);
Expand All @@ -366,7 +366,7 @@ describe('RelayContainer.setVariables', function() {
});

it('invokes the callback with the component as `this`', () => {
const mockFunction = jest.genMockFunction().mockImplementation(function() {
const mockFunction = jest.fn(function() {
expect(this.constructor).toBe(MockComponent);
});
mockInstance.setVariables({site: 'www'}, mockFunction);
Expand Down Expand Up @@ -406,11 +406,11 @@ describe('RelayContainer.setVariables', function() {
let prepareVariables;

beforeEach(() => {
entityQuery = jest.genMockFunction().mockImplementation(
entityQuery = jest.fn(
() => Relay.QL`fragment on Node{url(site:$site)}`
);
render = jest.genMockFunction().mockImplementation(() => <div />);
prepareVariables = jest.genMockFunction().mockImplementation(
render = jest.fn(() => <div />);
prepareVariables = jest.fn(
(variables, route) => variables
);

Expand Down Expand Up @@ -467,7 +467,7 @@ describe('RelayContainer.setVariables', function() {
});

it('ignores `setState` from callback when request aborts', () => {
const mockCallback = jest.genMockFunction()
const mockCallback = jest.fn()
.mockImplementation(readyState => {
if (readyState.mounted) {
this.setState({isAborted: true});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('RelayRenderer.onReadyStateChange', () => {
let onReadyStateChange;

beforeEach(() => {
onReadyStateChange = jest.genMockFunction();
onReadyStateChange = jest.fn();
ReactDOM.render(
<RelayRenderer
Container={MockContainer}
Expand Down
14 changes: 7 additions & 7 deletions src/container/__tests__/RelayRenderer_render-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('RelayRenderer.render', () => {

it('renders when mounted before a request is sent', () => {
const initialView = <div />;
const render = jest.genMockFunction().mockReturnValue(initialView);
const render = jest.fn(() => initialView);
renderElement(
<RelayRenderer
Container={MockContainer}
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('RelayRenderer.render', () => {
});

it('renders whenever updated after request is sent', () => {
const render = jest.genMockFunction();
const render = jest.fn();
function update() {
renderElement(
<RelayRenderer
Expand All @@ -164,7 +164,7 @@ describe('RelayRenderer.render', () => {
});

it('renders once after each ready state change', () => {
const render = jest.genMockFunction();
const render = jest.fn();

renderElement(
<RelayRenderer
Expand Down Expand Up @@ -194,12 +194,12 @@ describe('RelayRenderer.render', () => {

beforeEach(() => {
const storeData = environment.getStoreData();
storeData.initializeGarbageCollector(jest.genMockFunction());
storeData.initializeGarbageCollector(jest.fn());
garbageCollector = storeData.getGarbageCollector();
});

it('acquires a GC hold when mounted', () => {
garbageCollector.acquireHold = jest.genMockFunction();
garbageCollector.acquireHold = jest.fn();
renderElement(
<RelayRenderer
Container={MockContainer}
Expand All @@ -211,9 +211,9 @@ describe('RelayRenderer.render', () => {
});

it('releases its GC hold when unmounted', () => {
const release = jest.genMockFunction();
const release = jest.fn();
garbageCollector.acquireHold =
jest.genMockFunction().mockReturnValue({release});
jest.fn(() => ({release}));
renderElement(
<RelayRenderer
Container={MockContainer}
Expand Down
2 changes: 1 addition & 1 deletion src/container/__tests__/RelayRenderer_renderArgs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('RelayRenderer.renderArgs', () => {
queryConfig = RelayQueryConfig.genMockInstance();
environment = new RelayEnvironment();

render = jest.genMockFunction();
render = jest.fn();
ReactDOM.render(
<RelayRenderer
Container={MockContainer}
Expand Down
8 changes: 4 additions & 4 deletions src/container/__tests__/RelayRenderer_requests-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ describe('RelayRenderer', function() {
});

it('calls `onForceFetch` hook if supplied', () => {
const onForceFetch = jest.genMockFunction();
const onPrimeCache = jest.genMockFunction();
const onForceFetch = jest.fn();
const onPrimeCache = jest.fn();

ReactDOM.render(
<RelayRenderer
Expand All @@ -175,8 +175,8 @@ describe('RelayRenderer', function() {

it('calls `onPrimeCache` hook if supplied', () => {
const anotherQueryConfig = RelayQueryConfig.genMockInstance();
const onForceFetch = jest.genMockFunction();
const onPrimeCache = jest.genMockFunction();
const onForceFetch = jest.fn();
const onPrimeCache = jest.fn();

ReactDOM.render(
<RelayRenderer
Expand Down
2 changes: 1 addition & 1 deletion src/container/__tests__/RelayRenderer_validation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('RelayRenderer.validation', () => {
queryConfig = RelayQueryConfig.genMockInstance();
environment = new RelayEnvironment();

console.error = jest.genMockFunction().mockImplementation(message => {
console.error = jest.fn(message => {
throw new Error(message.replace(/Composite propType/, 'propType'));
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/store/__mocks__/GraphQLQueryRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ GraphQLQueryRunner.mockImplementation(function() {
this.run.mockImplementation((...args) => {
const request = genMockRequest(args);
const returnValue = {
abort: jest.genMockFunction().mockImplementation(() => {
abort: jest.fn(() => {
resolveImmediate(request.abort);
}),
};
Expand All @@ -69,7 +69,7 @@ GraphQLQueryRunner.mockImplementation(function() {
this.forceFetch.mockImplementation((...args) => {
const request = genMockRequest(args);
const returnValue = {
abort: jest.genMockFunction().mockImplementation(() => {
abort: jest.fn(() => {
resolveImmediate(request.abort);
}),
};
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/store/__mocks__/GraphQLStoreChangeEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const GraphQLStoreChangeEmitter = jest.genMockFromModule('GraphQLStoreChangeEmit
GraphQLStoreChangeEmitter.mockImplementation(function() {
this.addListenerForIDs.mock.remove = [];
this.addListenerForIDs.mockImplementation(() => {
const returnValue = {remove: jest.genMockFunction()};
const returnValue = {remove: jest.fn()};
this.addListenerForIDs.mock.remove.push(
returnValue.remove
);
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/store/__mocks__/GraphQLStoreQueryResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class GraphQLStoreQueryResolver {
queryFragment,
store,
};
this.resolve = jest.genMockFunction().mockImplementation((...args) => {
this.resolve = jest.fn((...args) => {
const mockConstructor = GraphQLStoreQueryResolver.mock;
const mockResolve =
mockConstructor.resolveImplementations[this.mock.index] ||
mockConstructor.defaultResolveImplementation;
return mockResolve.apply(this, args);
});
this.reset = jest.genMockFunction();
this.dispose = jest.genMockFunction();
this.reset = jest.fn();
this.dispose = jest.fn();
mockInstances.push(this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/store/__mocks__/GraphQLStoreRangeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Object.getOwnPropertyNames(GraphQLStoreRangeUtils.prototype).forEach(name => {
const property = GraphQLStoreRangeUtils.prototype[name];
if (typeof property === 'function') {
GraphQLStoreRangeUtils.prototype[name] =
jest.genMockFunction().mockImplementation(property);
jest.fn(property);
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/store/__mocks__/GraphQLStoreTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const GraphQLStoreTestUtils = {
/* globals expect: false */
const consoleFunction = console[type];
const whitelistedStrings = [];
const mockFunction = jest.genMockFunction().mockImplementation(
const mockFunction = jest.fn(
function(...args) {
const formatString = args[0];
if (whitelistedStrings.indexOf(formatString) >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/store/__mocks__/generateClientID.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

let count = 1;

const generateClientID = jest.genMockFunction().mockImplementation(
const generateClientID = jest.fn(
() => { return 'client:' + count++; }
);

Expand Down
6 changes: 3 additions & 3 deletions src/legacy/store/__tests__/GraphQLQueryRunner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('GraphQLQueryRunner', () => {
supports: () => true,
});

mockCallback = jest.genMockFunction();
mockCallback = jest.fn();
mockQuerySet = {
foo: getNode(Relay.QL`query{viewer{actor{id,name}}}`),
bar: getNode(Relay.QL`query{node(id:"4"){id,name}}`),
Expand Down Expand Up @@ -307,9 +307,9 @@ describe('GraphQLQueryRunner', () => {
it('is ready if required data is in disk cache', () => {
diffRelayQuery.mockImplementation(query => [query]);
RelayStoreData.prototype.hasCacheManager =
jest.genMockFunction().mockImplementation(() => true);
jest.fn(() => true);
RelayStoreData.prototype.readFromDiskCache =
jest.genMockFunction().mockImplementation((queries, callback) => {
jest.fn((queries, callback) => {
callback.onSuccess();
});
mockSplitDeferredQueries();
Expand Down
Loading

0 comments on commit 8547af9

Please sign in to comment.