Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove jest.genMockFn and jest.genMockFunction #6173

Merged
merged 3 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
([##5733](https://github.com/facebook/jest/pull/#5733))
* `[docs]` Improve Snapshot Testing Guide
([#5812](https://github.com/facebook/jest/issues/5812))
* `[jest-runtime]` [**BREAKING**] Remove `jest.genMockFn` and
`jest.genMockFunction` ([#6173](https://github.com/facebook/jest/pull/6173))

## 22.4.2

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment-jsdom/src/__mocks__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JSDOMEnvironment.mockImplementation(function(config) {
this.global = {
JSON,
console: {},
mockClearTimers: jest.genMockFn(),
mockClearTimers: jest.fn(),
};

const globalValues = Object.assign({}, config.globals);
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,8 @@ class Runtime {
dontMock: unmock,
enableAutomock,
fn,
genMockFn: fn,
genMockFromModule: (moduleName: string) =>
this._generateMock(from, moduleName),
genMockFunction: fn,
isMockFunction: this._moduleMocker.isMockFunction,
mock,
requireActual: localRequire.requireActual,
Expand Down
94 changes: 47 additions & 47 deletions packages/jest-util/src/__tests__/fake_timers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('FakeTimers', () => {
});

it('does nothing when no ticks have been scheduled', () => {
const nextTick = jest.genMockFn();
const nextTick = jest.fn();
const global = {
process: {
nextTick,
Expand All @@ -145,7 +145,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.process.nextTick(mock1);
expect(mock1.mock.calls.length).toBe(0);

Expand All @@ -157,7 +157,7 @@ describe('FakeTimers', () => {
});

it('cancels a callback even from native nextTick', () => {
const nativeNextTick = jest.genMockFn();
const nativeNextTick = jest.fn();

const global = {
process: {
Expand All @@ -168,7 +168,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.process.nextTick(mock1);
timers.runAllTicks();
expect(mock1.mock.calls.length).toBe(1);
Expand All @@ -181,7 +181,7 @@ describe('FakeTimers', () => {
});

it('cancels a callback even from native setImmediate', () => {
const nativeSetImmediate = jest.genMockFn();
const nativeSetImmediate = jest.fn();

const global = {
process,
Expand All @@ -191,7 +191,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.setImmediate(mock1);
timers.runAllImmediates();
expect(mock1.mock.calls.length).toBe(1);
Expand All @@ -203,7 +203,7 @@ describe('FakeTimers', () => {
});

it('doesnt run a tick callback if native nextTick already did', () => {
const nativeNextTick = jest.genMockFn();
const nativeNextTick = jest.fn();

const global = {
process: {
Expand All @@ -214,7 +214,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.process.nextTick(mock1);

// Emulate native nextTick running...
Expand All @@ -227,7 +227,7 @@ describe('FakeTimers', () => {
});

it('doesnt run immediate if native setImmediate already did', () => {
const nativeSetImmediate = jest.genMockFn();
const nativeSetImmediate = jest.fn();

const global = {
process,
Expand All @@ -237,7 +237,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.setImmediate(mock1);

// Emulate native setImmediate running...
Expand All @@ -250,7 +250,7 @@ describe('FakeTimers', () => {
});

it('native doesnt run immediate if fake already did', () => {
const nativeSetImmediate = jest.genMockFn();
const nativeSetImmediate = jest.fn();

const global = {
process,
Expand All @@ -260,7 +260,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.setImmediate(mock1);

//run all immediates now
Expand Down Expand Up @@ -358,7 +358,7 @@ describe('FakeTimers', () => {
});

it('does nothing when no timers have been scheduled', () => {
const nativeSetTimeout = jest.genMockFn();
const nativeSetTimeout = jest.fn();
const global = {
process,
setTimeout: nativeSetTimeout,
Expand All @@ -374,7 +374,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const fn = jest.genMockFn();
const fn = jest.fn();
global.setTimeout(fn, 0);
expect(fn.mock.calls.length).toBe(0);

Expand All @@ -390,15 +390,15 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const fn = jest.genMockFn();
const fn = jest.fn();
global.setTimeout(fn, 0, 'mockArg1', 'mockArg2');

timers.runAllTimers();
expect(fn.mock.calls).toEqual([['mockArg1', 'mockArg2']]);
});

it('doesnt pass the callback to native setTimeout', () => {
const nativeSetTimeout = jest.genMockFn();
const nativeSetTimeout = jest.fn();

const global = {
process,
Expand All @@ -408,7 +408,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.setTimeout(mock1, 0);

timers.runAllTimers();
Expand Down Expand Up @@ -445,7 +445,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const fn = jest.genMockFn();
const fn = jest.fn();
global.setTimeout(() => {
process.nextTick(fn);
}, 0);
Expand Down Expand Up @@ -535,7 +535,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.setTimeout(mock1, 100);

timers.reset();
Expand All @@ -548,7 +548,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.setInterval(mock1, 200);

timers.reset();
Expand All @@ -566,7 +566,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.process.nextTick(mock1);
global.setImmediate(mock1);

Expand All @@ -581,7 +581,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const mock1 = jest.genMockFn();
const mock1 = jest.fn();
global.setTimeout(mock1, 100);
timers.advanceTimersByTime(50);

Expand All @@ -595,7 +595,7 @@ describe('FakeTimers', () => {

describe('runOnlyPendingTimers', () => {
it('runs all timers in order', () => {
const nativeSetImmediate = jest.genMockFn();
const nativeSetImmediate = jest.fn();

const global = {
process,
Expand Down Expand Up @@ -653,7 +653,7 @@ describe('FakeTimers', () => {
const timers = new FakeTimers({global, moduleMocker, timerConfig});
timers.useFakeTimers();

const fn = jest.genMockFn();
const fn = jest.fn();
const timer = global.setTimeout(fn, 10);
global.setTimeout(() => {
global.clearTimeout(timer);
Expand All @@ -666,10 +666,10 @@ describe('FakeTimers', () => {

describe('runWithRealTimers', () => {
it('executes callback with native timers', () => {
const nativeClearInterval = jest.genMockFn();
const nativeClearTimeout = jest.genMockFn();
const nativeSetInterval = jest.genMockFn();
const nativeSetTimeout = jest.genMockFn();
const nativeClearInterval = jest.fn();
const nativeClearTimeout = jest.fn();
const nativeSetInterval = jest.fn();
const nativeSetTimeout = jest.fn();

const global = {
clearInterval: nativeClearInterval,
Expand Down Expand Up @@ -711,10 +711,10 @@ describe('FakeTimers', () => {
});

it('resets mock timers after executing callback', () => {
const nativeClearInterval = jest.genMockFn();
const nativeClearTimeout = jest.genMockFn();
const nativeSetInterval = jest.genMockFn();
const nativeSetTimeout = jest.genMockFn();
const nativeClearInterval = jest.fn();
const nativeClearTimeout = jest.fn();
const nativeSetInterval = jest.fn();
const nativeSetTimeout = jest.fn();

const global = {
clearInterval: nativeClearInterval,
Expand Down Expand Up @@ -772,7 +772,7 @@ describe('FakeTimers', () => {
});

it('resets mock timer functions even if callback throws', () => {
const nativeSetTimeout = jest.genMockFn();
const nativeSetTimeout = jest.fn();
const global = {
process,
setTimeout: nativeSetTimeout,
Expand All @@ -797,10 +797,10 @@ describe('FakeTimers', () => {

describe('useRealTimers', () => {
it('resets native timer APIs', () => {
const nativeSetTimeout = jest.genMockFn();
const nativeSetInterval = jest.genMockFn();
const nativeClearTimeout = jest.genMockFn();
const nativeClearInterval = jest.genMockFn();
const nativeSetTimeout = jest.fn();
const nativeSetInterval = jest.fn();
const nativeClearTimeout = jest.fn();
const nativeClearInterval = jest.fn();

const global = {
clearInterval: nativeClearInterval,
Expand Down Expand Up @@ -828,7 +828,7 @@ describe('FakeTimers', () => {
});

it('resets native process.nextTick when present', () => {
const nativeProcessNextTick = jest.genMockFn();
const nativeProcessNextTick = jest.fn();

const global = {
process: {nextTick: nativeProcessNextTick},
Expand All @@ -846,8 +846,8 @@ describe('FakeTimers', () => {
});

it('resets native setImmediate when present', () => {
const nativeSetImmediate = jest.genMockFn();
const nativeClearImmediate = jest.genMockFn();
const nativeSetImmediate = jest.fn();
const nativeClearImmediate = jest.fn();

const global = {
clearImmediate: nativeClearImmediate,
Expand All @@ -871,10 +871,10 @@ describe('FakeTimers', () => {

describe('useFakeTimers', () => {
it('resets mock timer APIs', () => {
const nativeSetTimeout = jest.genMockFn();
const nativeSetInterval = jest.genMockFn();
const nativeClearTimeout = jest.genMockFn();
const nativeClearInterval = jest.genMockFn();
const nativeSetTimeout = jest.fn();
const nativeSetInterval = jest.fn();
const nativeClearTimeout = jest.fn();
const nativeClearInterval = jest.fn();

const global = {
clearInterval: nativeClearInterval,
Expand Down Expand Up @@ -902,7 +902,7 @@ describe('FakeTimers', () => {
});

it('resets mock process.nextTick when present', () => {
const nativeProcessNextTick = jest.genMockFn();
const nativeProcessNextTick = jest.fn();

const global = {
process: {nextTick: nativeProcessNextTick},
Expand All @@ -920,8 +920,8 @@ describe('FakeTimers', () => {
});

it('resets mock setImmediate when present', () => {
const nativeSetImmediate = jest.genMockFn();
const nativeClearImmediate = jest.genMockFn();
const nativeSetImmediate = jest.fn();
const nativeClearImmediate = jest.fn();

const global = {
clearImmediate: nativeClearImmediate,
Expand Down
5 changes: 1 addition & 4 deletions types/Jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @flow
*/

type GenMockFn = (implementation?: Function) => JestMockFn;
type JestMockFn = Function;

export type LocalModuleRequire = (moduleName: string) => any;
Expand All @@ -23,10 +22,8 @@ export type Jest = {|
doMock(moduleName: string, moduleFactory?: any): Jest,
dontMock(moduleName: string): Jest,
enableAutomock(): Jest,
fn: GenMockFn,
genMockFn: GenMockFn,
fn: (implementation?: Function) => JestMockFn,
genMockFromModule(moduleName: string): any,
genMockFunction: GenMockFn,
isMockFunction(fn: Function): boolean,
mock(moduleName: string, moduleFactory?: any, options?: Object): Jest,
requireActual: LocalModuleRequire,
Expand Down