From 50d590a5cb7619cc4416a44212d5b6005edb7bcf Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Sat, 29 May 2021 23:34:41 +0900 Subject: [PATCH] fix: Fix `jest-mock` `fn` and `spyOn`. (#11480) --- CHANGELOG.md | 6 ++++++ packages/jest-mock/src/__tests__/index.test.ts | 9 ++++++++- packages/jest-mock/src/index.ts | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e13dbce1292e..13a4077437eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ ### Performance +## 27.0.3 + +### Fixes + +- `[jest-mock]` Fixed `fn` and `spyOn` exports ([#11480](https://github.com/facebook/jest/pull/11480)) + ## 27.0.2 ### Features diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index d68857294cb4..0266d24f2b7b 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -9,7 +9,7 @@ /* eslint-disable local/ban-types-eventually, local/prefer-rest-params-eventually */ import vm, {Context} from 'vm'; -import {ModuleMocker} from '../'; +import {ModuleMocker, fn, spyOn} from '../'; describe('moduleMocker', () => { let moduleMocker: ModuleMocker; @@ -1439,3 +1439,10 @@ describe('moduleMocker', () => { }); }); }); + +test('`fn` and `spyOn` do not throw', () => { + expect(() => { + fn(); + spyOn({apple: () => {}}, 'apple'); + }).not.toThrow(); +}); diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index 13f229f76de4..1b0330421124 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -1112,5 +1112,5 @@ export class ModuleMocker { const JestMock = new ModuleMocker(global); -export const fn = JestMock.fn; -export const spyOn = JestMock.spyOn; +export const fn = JestMock.fn.bind(JestMock); +export const spyOn = JestMock.spyOn.bind(JestMock);