Skip to content

Commit 50d590a

Browse files
authored
fix: Fix jest-mock fn and spyOn. (#11480)
1 parent e9802d3 commit 50d590a

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
### Performance
1010

11+
## 27.0.3
12+
13+
### Fixes
14+
15+
- `[jest-mock]` Fixed `fn` and `spyOn` exports ([#11480](https://github.com/facebook/jest/pull/11480))
16+
1117
## 27.0.2
1218

1319
### Features

packages/jest-mock/src/__tests__/index.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/* eslint-disable local/ban-types-eventually, local/prefer-rest-params-eventually */
1010

1111
import vm, {Context} from 'vm';
12-
import {ModuleMocker} from '../';
12+
import {ModuleMocker, fn, spyOn} from '../';
1313

1414
describe('moduleMocker', () => {
1515
let moduleMocker: ModuleMocker;
@@ -1439,3 +1439,10 @@ describe('moduleMocker', () => {
14391439
});
14401440
});
14411441
});
1442+
1443+
test('`fn` and `spyOn` do not throw', () => {
1444+
expect(() => {
1445+
fn();
1446+
spyOn({apple: () => {}}, 'apple');
1447+
}).not.toThrow();
1448+
});

packages/jest-mock/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1112,5 +1112,5 @@ export class ModuleMocker {
11121112

11131113
const JestMock = new ModuleMocker(global);
11141114

1115-
export const fn = JestMock.fn;
1116-
export const spyOn = JestMock.spyOn;
1115+
export const fn = JestMock.fn.bind(JestMock);
1116+
export const spyOn = JestMock.spyOn.bind(JestMock);

0 commit comments

Comments
 (0)