Skip to content

Commit 08f7904

Browse files
SimenBcpojer
authored andcommitted
chore: remove jest.genMockFn and jest.genMockFunction (jestjs#6173)
* chore: remove `jest.genMockFn` * link to PR in changelog * also `jest.genMockFunction`
1 parent fef9032 commit 08f7904

File tree

5 files changed

+51
-54
lines changed

5 files changed

+51
-54
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@
179179
([##5733](https://github.com/facebook/jest/pull/#5733))
180180
* `[docs]` Improve Snapshot Testing Guide
181181
([#5812](https://github.com/facebook/jest/issues/5812))
182+
* `[jest-runtime]` [**BREAKING**] Remove `jest.genMockFn` and
183+
`jest.genMockFunction` ([#6173](https://github.com/facebook/jest/pull/6173))
182184

183185
## 22.4.2
184186

packages/jest-environment-jsdom/src/__mocks__/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ JSDOMEnvironment.mockImplementation(function(config) {
1414
this.global = {
1515
JSON,
1616
console: {},
17-
mockClearTimers: jest.genMockFn(),
17+
mockClearTimers: jest.fn(),
1818
};
1919

2020
const globalValues = Object.assign({}, config.globals);

packages/jest-runtime/src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,10 +844,8 @@ class Runtime {
844844
dontMock: unmock,
845845
enableAutomock,
846846
fn,
847-
genMockFn: fn,
848847
genMockFromModule: (moduleName: string) =>
849848
this._generateMock(from, moduleName),
850-
genMockFunction: fn,
851849
isMockFunction: this._moduleMocker.isMockFunction,
852850
mock,
853851
requireActual: localRequire.requireActual,

packages/jest-util/src/__tests__/fake_timers.test.js

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('FakeTimers', () => {
121121
});
122122

123123
it('does nothing when no ticks have been scheduled', () => {
124-
const nextTick = jest.genMockFn();
124+
const nextTick = jest.fn();
125125
const global = {
126126
process: {
127127
nextTick,
@@ -145,7 +145,7 @@ describe('FakeTimers', () => {
145145
const timers = new FakeTimers({global, moduleMocker, timerConfig});
146146
timers.useFakeTimers();
147147

148-
const mock1 = jest.genMockFn();
148+
const mock1 = jest.fn();
149149
global.process.nextTick(mock1);
150150
expect(mock1.mock.calls.length).toBe(0);
151151

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

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

162162
const global = {
163163
process: {
@@ -168,7 +168,7 @@ describe('FakeTimers', () => {
168168
const timers = new FakeTimers({global, moduleMocker, timerConfig});
169169
timers.useFakeTimers();
170170

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

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

186186
const global = {
187187
process,
@@ -191,7 +191,7 @@ describe('FakeTimers', () => {
191191
const timers = new FakeTimers({global, moduleMocker, timerConfig});
192192
timers.useFakeTimers();
193193

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

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

208208
const global = {
209209
process: {
@@ -214,7 +214,7 @@ describe('FakeTimers', () => {
214214
const timers = new FakeTimers({global, moduleMocker, timerConfig});
215215
timers.useFakeTimers();
216216

217-
const mock1 = jest.genMockFn();
217+
const mock1 = jest.fn();
218218
global.process.nextTick(mock1);
219219

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

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

232232
const global = {
233233
process,
@@ -237,7 +237,7 @@ describe('FakeTimers', () => {
237237
const timers = new FakeTimers({global, moduleMocker, timerConfig});
238238
timers.useFakeTimers();
239239

240-
const mock1 = jest.genMockFn();
240+
const mock1 = jest.fn();
241241
global.setImmediate(mock1);
242242

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

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

255255
const global = {
256256
process,
@@ -260,7 +260,7 @@ describe('FakeTimers', () => {
260260
const timers = new FakeTimers({global, moduleMocker, timerConfig});
261261
timers.useFakeTimers();
262262

263-
const mock1 = jest.genMockFn();
263+
const mock1 = jest.fn();
264264
global.setImmediate(mock1);
265265

266266
//run all immediates now
@@ -358,7 +358,7 @@ describe('FakeTimers', () => {
358358
});
359359

360360
it('does nothing when no timers have been scheduled', () => {
361-
const nativeSetTimeout = jest.genMockFn();
361+
const nativeSetTimeout = jest.fn();
362362
const global = {
363363
process,
364364
setTimeout: nativeSetTimeout,
@@ -374,7 +374,7 @@ describe('FakeTimers', () => {
374374
const timers = new FakeTimers({global, moduleMocker, timerConfig});
375375
timers.useFakeTimers();
376376

377-
const fn = jest.genMockFn();
377+
const fn = jest.fn();
378378
global.setTimeout(fn, 0);
379379
expect(fn.mock.calls.length).toBe(0);
380380

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

393-
const fn = jest.genMockFn();
393+
const fn = jest.fn();
394394
global.setTimeout(fn, 0, 'mockArg1', 'mockArg2');
395395

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

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

403403
const global = {
404404
process,
@@ -408,7 +408,7 @@ describe('FakeTimers', () => {
408408
const timers = new FakeTimers({global, moduleMocker, timerConfig});
409409
timers.useFakeTimers();
410410

411-
const mock1 = jest.genMockFn();
411+
const mock1 = jest.fn();
412412
global.setTimeout(mock1, 0);
413413

414414
timers.runAllTimers();
@@ -445,7 +445,7 @@ describe('FakeTimers', () => {
445445
const timers = new FakeTimers({global, moduleMocker, timerConfig});
446446
timers.useFakeTimers();
447447

448-
const fn = jest.genMockFn();
448+
const fn = jest.fn();
449449
global.setTimeout(() => {
450450
process.nextTick(fn);
451451
}, 0);
@@ -535,7 +535,7 @@ describe('FakeTimers', () => {
535535
const timers = new FakeTimers({global, moduleMocker, timerConfig});
536536
timers.useFakeTimers();
537537

538-
const mock1 = jest.genMockFn();
538+
const mock1 = jest.fn();
539539
global.setTimeout(mock1, 100);
540540

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

551-
const mock1 = jest.genMockFn();
551+
const mock1 = jest.fn();
552552
global.setInterval(mock1, 200);
553553

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

569-
const mock1 = jest.genMockFn();
569+
const mock1 = jest.fn();
570570
global.process.nextTick(mock1);
571571
global.setImmediate(mock1);
572572

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

584-
const mock1 = jest.genMockFn();
584+
const mock1 = jest.fn();
585585
global.setTimeout(mock1, 100);
586586
timers.advanceTimersByTime(50);
587587

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

596596
describe('runOnlyPendingTimers', () => {
597597
it('runs all timers in order', () => {
598-
const nativeSetImmediate = jest.genMockFn();
598+
const nativeSetImmediate = jest.fn();
599599

600600
const global = {
601601
process,
@@ -653,7 +653,7 @@ describe('FakeTimers', () => {
653653
const timers = new FakeTimers({global, moduleMocker, timerConfig});
654654
timers.useFakeTimers();
655655

656-
const fn = jest.genMockFn();
656+
const fn = jest.fn();
657657
const timer = global.setTimeout(fn, 10);
658658
global.setTimeout(() => {
659659
global.clearTimeout(timer);
@@ -666,10 +666,10 @@ describe('FakeTimers', () => {
666666

667667
describe('runWithRealTimers', () => {
668668
it('executes callback with native timers', () => {
669-
const nativeClearInterval = jest.genMockFn();
670-
const nativeClearTimeout = jest.genMockFn();
671-
const nativeSetInterval = jest.genMockFn();
672-
const nativeSetTimeout = jest.genMockFn();
669+
const nativeClearInterval = jest.fn();
670+
const nativeClearTimeout = jest.fn();
671+
const nativeSetInterval = jest.fn();
672+
const nativeSetTimeout = jest.fn();
673673

674674
const global = {
675675
clearInterval: nativeClearInterval,
@@ -711,10 +711,10 @@ describe('FakeTimers', () => {
711711
});
712712

713713
it('resets mock timers after executing callback', () => {
714-
const nativeClearInterval = jest.genMockFn();
715-
const nativeClearTimeout = jest.genMockFn();
716-
const nativeSetInterval = jest.genMockFn();
717-
const nativeSetTimeout = jest.genMockFn();
714+
const nativeClearInterval = jest.fn();
715+
const nativeClearTimeout = jest.fn();
716+
const nativeSetInterval = jest.fn();
717+
const nativeSetTimeout = jest.fn();
718718

719719
const global = {
720720
clearInterval: nativeClearInterval,
@@ -772,7 +772,7 @@ describe('FakeTimers', () => {
772772
});
773773

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

798798
describe('useRealTimers', () => {
799799
it('resets native timer APIs', () => {
800-
const nativeSetTimeout = jest.genMockFn();
801-
const nativeSetInterval = jest.genMockFn();
802-
const nativeClearTimeout = jest.genMockFn();
803-
const nativeClearInterval = jest.genMockFn();
800+
const nativeSetTimeout = jest.fn();
801+
const nativeSetInterval = jest.fn();
802+
const nativeClearTimeout = jest.fn();
803+
const nativeClearInterval = jest.fn();
804804

805805
const global = {
806806
clearInterval: nativeClearInterval,
@@ -828,7 +828,7 @@ describe('FakeTimers', () => {
828828
});
829829

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

833833
const global = {
834834
process: {nextTick: nativeProcessNextTick},
@@ -846,8 +846,8 @@ describe('FakeTimers', () => {
846846
});
847847

848848
it('resets native setImmediate when present', () => {
849-
const nativeSetImmediate = jest.genMockFn();
850-
const nativeClearImmediate = jest.genMockFn();
849+
const nativeSetImmediate = jest.fn();
850+
const nativeClearImmediate = jest.fn();
851851

852852
const global = {
853853
clearImmediate: nativeClearImmediate,
@@ -871,10 +871,10 @@ describe('FakeTimers', () => {
871871

872872
describe('useFakeTimers', () => {
873873
it('resets mock timer APIs', () => {
874-
const nativeSetTimeout = jest.genMockFn();
875-
const nativeSetInterval = jest.genMockFn();
876-
const nativeClearTimeout = jest.genMockFn();
877-
const nativeClearInterval = jest.genMockFn();
874+
const nativeSetTimeout = jest.fn();
875+
const nativeSetInterval = jest.fn();
876+
const nativeClearTimeout = jest.fn();
877+
const nativeClearInterval = jest.fn();
878878

879879
const global = {
880880
clearInterval: nativeClearInterval,
@@ -902,7 +902,7 @@ describe('FakeTimers', () => {
902902
});
903903

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

907907
const global = {
908908
process: {nextTick: nativeProcessNextTick},
@@ -920,8 +920,8 @@ describe('FakeTimers', () => {
920920
});
921921

922922
it('resets mock setImmediate when present', () => {
923-
const nativeSetImmediate = jest.genMockFn();
924-
const nativeClearImmediate = jest.genMockFn();
923+
const nativeSetImmediate = jest.fn();
924+
const nativeClearImmediate = jest.fn();
925925

926926
const global = {
927927
clearImmediate: nativeClearImmediate,

types/Jest.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* @flow
88
*/
99

10-
type GenMockFn = (implementation?: Function) => JestMockFn;
1110
type JestMockFn = Function;
1211

1312
export type LocalModuleRequire = (moduleName: string) => any;
@@ -23,10 +22,8 @@ export type Jest = {|
2322
doMock(moduleName: string, moduleFactory?: any): Jest,
2423
dontMock(moduleName: string): Jest,
2524
enableAutomock(): Jest,
26-
fn: GenMockFn,
27-
genMockFn: GenMockFn,
25+
fn: (implementation?: Function) => JestMockFn,
2826
genMockFromModule(moduleName: string): any,
29-
genMockFunction: GenMockFn,
3027
isMockFunction(fn: Function): boolean,
3128
mock(moduleName: string, moduleFactory?: any, options?: Object): Jest,
3229
requireActual: LocalModuleRequire,

0 commit comments

Comments
 (0)