From c4cb6777beea7e0908182aebb5a3a4ae75ad43fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Mon, 19 Sep 2022 09:28:45 +0200 Subject: [PATCH 01/14] feat(@jest/mock): Add withImplementation For temporarily overriding mock implementations. --- CHANGELOG.md | 1 + packages/jest-mock/README.md | 6 +++ .../jest-mock/src/__tests__/index.test.ts | 53 +++++++++++++++++++ packages/jest-mock/src/index.ts | 40 ++++++++++++++ 4 files changed, 100 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 619a67e91df4..f3fc50878150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[@jest/mock]` Add `withImplementation` method for temporarily overriding a mock. - `[@jest/environment, jest-runtime]` Allow `jest.requireActual` and `jest.requireMock` to take a type argument ([#13253](https://github.com/facebook/jest/pull/13253)) - `[@jest/environment]` Allow `jest.mock` and `jest.doMock` to take a type argument ([#13254](https://github.com/facebook/jest/pull/13254)) - `[@jest/fake-timers]` Add `jest.now()` to return the current fake clock time ([#13244](https://github.com/facebook/jest/pull/13244), [13246](https://github.com/facebook/jest/pull/13246)) diff --git a/packages/jest-mock/README.md b/packages/jest-mock/README.md index 5bc75093f8fa..5ec503f64e39 100644 --- a/packages/jest-mock/README.md +++ b/packages/jest-mock/README.md @@ -98,3 +98,9 @@ In case both `.mockImplementationOnce()` / `.mockImplementation()` and `.mockRet - if the last call is `.mockReturnValueOnce()` or `.mockReturnValue()`, use the specific return value or default return value. If specific return values are used up or no default return value is set, fall back to try `.mockImplementation()`; - if the last call is `.mockImplementationOnce()` or `.mockImplementation()`, run the specific implementation and return the result or run default implementation and return the result. + +##### `.withImplementation(function, callback)` + +Temporarily overrides the default mock implementation within the callback, then restores it's previous implementation. + +If the callback is async or returns a promise like object, `withImplementation` will return a promise. Awaiting the promise will await the callback and reset the implementation. diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index 6b9f716d7ef0..9f1efe45f5e1 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -1073,6 +1073,59 @@ describe('moduleMocker', () => { }); }); + describe('withImplementation', () => { + it('sets an implementation which is available within the callback', async () => { + const mock1 = jest.fn(); + const mock2 = jest.fn(); + + const Module = jest.fn(() => ({someFn: mock1})); + const testFn = function () { + const m = new Module(); + m.someFn(); + }; + + Module.withImplementation( + () => ({someFn: mock2}), + () => { + testFn(); + expect(mock2).toHaveBeenCalled(); + expect(mock1).not.toHaveBeenCalled(); + }, + ); + + testFn(); + expect(mock1).toHaveBeenCalled(); + }); + + it('returns a promise if the provided callback is asynchronous', async () => { + const mock1 = jest.fn(); + const mock2 = jest.fn(); + + const Module = jest.fn(() => ({someFn: mock1})); + const testFn = function () { + const m = new Module(); + m.someFn(); + }; + + const promise = Module.withImplementation( + () => ({someFn: mock2}), + async () => { + testFn(); + expect(mock2).toHaveBeenCalled(); + expect(mock1).not.toHaveBeenCalled(); + }, + ); + + // Is there a better way to detect a promise? + expect(typeof promise.then).toBe('function'); + + await promise; + + testFn(); + expect(mock1).toHaveBeenCalled(); + }); + }); + test('mockReturnValue does not override mockImplementationOnce', () => { const mockFn = jest .fn() diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index 69319a05c583..f986d615d5b1 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -124,6 +124,12 @@ type RejectType = ReturnType extends PromiseLike ? unknown : never; +type WithImplementationSyncCallbackReturn = void | undefined; +type WithImplementationAsyncCallbackReturn = Promise; +type WithImplementationCallbackReturn = + | WithImplementationSyncCallbackReturn + | WithImplementationAsyncCallbackReturn; + export interface MockInstance { _isMockFunction: true; _protoImpl: Function; @@ -135,6 +141,12 @@ export interface MockInstance { mockRestore(): void; mockImplementation(fn: T): this; mockImplementationOnce(fn: T): this; + withImplementation( + fn: T, + callback: () => R, + ): R extends WithImplementationAsyncCallbackReturn + ? Promise + : undefined; mockName(name: string): this; mockReturnThis(): this; mockReturnValue(value: ReturnType): this; @@ -768,6 +780,34 @@ export class ModuleMocker { return f; }; + f.withImplementation = ( + fn: UnknownFunction, + callback: () => R, + // @ts-expect-error: Type guards are not advanced enough for this use case + ): R extends WithImplementationAsyncCallbackReturn + ? Promise + : undefined => { + // Remember previous mock implementation, then set new one + const mockConfig = this._ensureMockConfig(f); + const previousImplementation = mockConfig.mockImpl; + mockConfig.mockImpl = fn; + + const returnedValue = callback(); + + if ( + typeof returnedValue === 'object' && + returnedValue !== null && + typeof returnedValue.then === 'function' + ) { + // @ts-expect-error: Type guards are not advanced enough for this use case + return returnedValue.then(() => { + mockConfig.mockImpl = previousImplementation; + }); + } else { + mockConfig.mockImpl = previousImplementation; + } + }; + f.mockImplementation = (fn: UnknownFunction) => { // next function call will use mock implementation return value const mockConfig = this._ensureMockConfig(f); From dd2bb3c8671d79febb203daadb38cdd3494d343e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Tue, 20 Sep 2022 08:44:35 +0200 Subject: [PATCH 02/14] Add docs for `mockFn.withImplementation` --- docs/MockFunctionAPI.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/MockFunctionAPI.md b/docs/MockFunctionAPI.md index 8e55737147d8..1941316fe081 100644 --- a/docs/MockFunctionAPI.md +++ b/docs/MockFunctionAPI.md @@ -478,6 +478,43 @@ test('async test', async () => { }); ``` +### `mockFn.withImplementation(fn, callback)` + +Accepts a function which should be temporarily used as the implementation of the mock while the callback is being executed. + +```js tab +test('test', () => { + const mock = jest.fn(() => 'outside callback'); + + mock.withImplementation( + () => 'inside callback', + () => { + mock(); // 'inside callback' + }, + ); + + mock(); // 'outside callback' +}); +``` + +`mockFn.withImplementation` can be used regardless of whether or not the callback is asynchronous (returns a promise like object). If the callback is asynchronous a promise will be returned. Awaiting the promise will await the callback and reset the implementation. + +```js +test('async test', async () => { + const mock = jest.fn(() => 'outside callback'); + + // We await this call since the callback is async + await mock.withImplementation( + () => 'inside callback', + async () => { + mock(); // 'inside callback' + }, + ); + + mock(); // 'outside callback' +}); +``` + ## TypeScript Usage :::tip From bc2643b59aee9fab55f66a2f32020edd36747cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Tue, 20 Sep 2022 08:50:24 +0200 Subject: [PATCH 03/14] Use util.types.isPromise in jest-mock test --- packages/jest-mock/src/__tests__/index.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index 9f1efe45f5e1..5a117482ff2c 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -8,6 +8,7 @@ /* eslint-disable local/ban-types-eventually, local/prefer-rest-params-eventually */ +import * as util from 'util'; import vm, {Context} from 'vm'; import {ModuleMocker, fn, mocked, spyOn} from '../'; @@ -1116,8 +1117,7 @@ describe('moduleMocker', () => { }, ); - // Is there a better way to detect a promise? - expect(typeof promise.then).toBe('function'); + expect(util.types.isPromise(promise)).toBe(true); await promise; From dcef50b2bd9f43f18aa5730f3e098acfdcebaa55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Tue, 20 Sep 2022 08:51:29 +0200 Subject: [PATCH 04/14] Fix incorrect usage of ```js tab``` Co-authored-by: Tom Mrazauskas --- docs/MockFunctionAPI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/MockFunctionAPI.md b/docs/MockFunctionAPI.md index 1941316fe081..88976445ef11 100644 --- a/docs/MockFunctionAPI.md +++ b/docs/MockFunctionAPI.md @@ -482,7 +482,7 @@ test('async test', async () => { Accepts a function which should be temporarily used as the implementation of the mock while the callback is being executed. -```js tab +```js test('test', () => { const mock = jest.fn(() => 'outside callback'); From 12fddb24d378881d03929a3ff6b74615f7f38951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Tue, 20 Sep 2022 09:18:37 +0200 Subject: [PATCH 05/14] Use function overload for types for `mock.withImplemenation` To avoid @ts-expect-error --- .../__typetests__/mock-functions.test.ts | 7 +++- packages/jest-mock/src/index.ts | 36 ++++++++----------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/jest-mock/__typetests__/mock-functions.test.ts b/packages/jest-mock/__typetests__/mock-functions.test.ts index 0c747c2642e0..20a9d9faa656 100644 --- a/packages/jest-mock/__typetests__/mock-functions.test.ts +++ b/packages/jest-mock/__typetests__/mock-functions.test.ts @@ -250,7 +250,12 @@ expectType Promise>>( ); expectError(fn(() => Promise.resolve('')).mockRejectedValueOnce()); -// jest.spyOn() +expectType(mockFn.withImplementation(mockFnImpl, () => {})); +expectType>( + mockFn.withImplementation(mockFnImpl, async () => {}), +); + +expectError(mockFn.withImplementation(mockFnImpl, () => {}).then()); const spiedArray = ['a', 'b']; diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index f986d615d5b1..d2312276bddc 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -124,12 +124,6 @@ type RejectType = ReturnType extends PromiseLike ? unknown : never; -type WithImplementationSyncCallbackReturn = void | undefined; -type WithImplementationAsyncCallbackReturn = Promise; -type WithImplementationCallbackReturn = - | WithImplementationSyncCallbackReturn - | WithImplementationAsyncCallbackReturn; - export interface MockInstance { _isMockFunction: true; _protoImpl: Function; @@ -141,12 +135,8 @@ export interface MockInstance { mockRestore(): void; mockImplementation(fn: T): this; mockImplementationOnce(fn: T): this; - withImplementation( - fn: T, - callback: () => R, - ): R extends WithImplementationAsyncCallbackReturn - ? Promise - : undefined; + withImplementation(fn: T, callback: () => Promise): Promise; + withImplementation(fn: T, callback: () => void): void; mockName(name: string): this; mockReturnThis(): this; mockReturnValue(value: ReturnType): this; @@ -780,13 +770,18 @@ export class ModuleMocker { return f; }; - f.withImplementation = ( - fn: UnknownFunction, - callback: () => R, - // @ts-expect-error: Type guards are not advanced enough for this use case - ): R extends WithImplementationAsyncCallbackReturn - ? Promise - : undefined => { + f.withImplementation = withImplementation.bind(this); + + function withImplementation(fn: T, callback: () => void): void; + function withImplementation( + fn: T, + callback: () => Promise, + ): Promise; + function withImplementation( + this: ModuleMocker, + fn: T, + callback: (() => void) | (() => Promise), + ): void | Promise { // Remember previous mock implementation, then set new one const mockConfig = this._ensureMockConfig(f); const previousImplementation = mockConfig.mockImpl; @@ -799,14 +794,13 @@ export class ModuleMocker { returnedValue !== null && typeof returnedValue.then === 'function' ) { - // @ts-expect-error: Type guards are not advanced enough for this use case return returnedValue.then(() => { mockConfig.mockImpl = previousImplementation; }); } else { mockConfig.mockImpl = previousImplementation; } - }; + } f.mockImplementation = (fn: UnknownFunction) => { // next function call will use mock implementation return value From bd99f781c1ec0b3c89c8ec0e5236fd41cb526f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Wed, 21 Sep 2022 09:20:34 +0200 Subject: [PATCH 06/14] Update packages/jest-mock/__typetests__/mock-functions.test.ts Co-authored-by: Tom Mrazauskas --- packages/jest-mock/__typetests__/mock-functions.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/jest-mock/__typetests__/mock-functions.test.ts b/packages/jest-mock/__typetests__/mock-functions.test.ts index 20a9d9faa656..43c689acb64f 100644 --- a/packages/jest-mock/__typetests__/mock-functions.test.ts +++ b/packages/jest-mock/__typetests__/mock-functions.test.ts @@ -255,7 +255,9 @@ expectType>( mockFn.withImplementation(mockFnImpl, async () => {}), ); -expectError(mockFn.withImplementation(mockFnImpl, () => {}).then()); +expectError(mockFn.withImplementation(mockFnImpl); + +// jest.spyOn() const spiedArray = ['a', 'b']; From 93087bcebd335ecf449a4218358c7fd53a1b4024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Fri, 23 Sep 2022 14:24:18 +0200 Subject: [PATCH 07/14] Update docs/MockFunctionAPI.md Co-authored-by: Simen Bekkhus --- docs/MockFunctionAPI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/MockFunctionAPI.md b/docs/MockFunctionAPI.md index 88976445ef11..43a95bb3192e 100644 --- a/docs/MockFunctionAPI.md +++ b/docs/MockFunctionAPI.md @@ -497,7 +497,7 @@ test('test', () => { }); ``` -`mockFn.withImplementation` can be used regardless of whether or not the callback is asynchronous (returns a promise like object). If the callback is asynchronous a promise will be returned. Awaiting the promise will await the callback and reset the implementation. +`mockFn.withImplementation` can be used regardless of whether or not the callback is asynchronous (returns a `thenable`). If the callback is asynchronous a promise will be returned. Awaiting the promise will await the callback and reset the implementation. ```js test('async test', async () => { From d252023d04dce6a9a5a41fd4e98c0cf58a932927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Fri, 23 Sep 2022 14:24:33 +0200 Subject: [PATCH 08/14] Update packages/jest-mock/README.md Co-authored-by: Simen Bekkhus --- packages/jest-mock/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-mock/README.md b/packages/jest-mock/README.md index 5ec503f64e39..41588a07b281 100644 --- a/packages/jest-mock/README.md +++ b/packages/jest-mock/README.md @@ -103,4 +103,4 @@ In case both `.mockImplementationOnce()` / `.mockImplementation()` and `.mockRet Temporarily overrides the default mock implementation within the callback, then restores it's previous implementation. -If the callback is async or returns a promise like object, `withImplementation` will return a promise. Awaiting the promise will await the callback and reset the implementation. +If the callback is async or returns a `thenable`, `withImplementation` will return a promise. Awaiting the promise will await the callback and reset the implementation. From c776293c0ec7e0efd2f97dad133723a96fe3f8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Fri, 23 Sep 2022 14:25:30 +0200 Subject: [PATCH 09/14] Update packages/jest-mock/src/__tests__/index.test.ts Remove redundant `async` Co-authored-by: Simen Bekkhus --- packages/jest-mock/src/__tests__/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index 5a117482ff2c..af6b6cf8093c 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -1075,7 +1075,7 @@ describe('moduleMocker', () => { }); describe('withImplementation', () => { - it('sets an implementation which is available within the callback', async () => { + it('sets an implementation which is available within the callback', () => { const mock1 = jest.fn(); const mock2 = jest.fn(); From 20300d8d7dfba9026b6845d83012f2d2df4003aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Fri, 23 Sep 2022 14:33:22 +0200 Subject: [PATCH 10/14] Update packages/jest-mock/src/index.ts Change promise detection expression to bail out earlier for `null` and `undefined` Co-authored-by: Simen Bekkhus --- packages/jest-mock/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index d2312276bddc..13b61c0f1541 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -790,8 +790,8 @@ export class ModuleMocker { const returnedValue = callback(); if ( + returnedValue != null && typeof returnedValue === 'object' && - returnedValue !== null && typeof returnedValue.then === 'function' ) { return returnedValue.then(() => { From 67a4671d12cafdfb3abc88a3b733314d1bb4b6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Fri, 23 Sep 2022 14:37:41 +0200 Subject: [PATCH 11/14] Add expect.assertions to jest-mock `withImplementation` tests --- packages/jest-mock/src/__tests__/index.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index af6b6cf8093c..27f7ba18369c 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -1096,6 +1096,8 @@ describe('moduleMocker', () => { testFn(); expect(mock1).toHaveBeenCalled(); + + expect.assertions(3); }); it('returns a promise if the provided callback is asynchronous', async () => { @@ -1123,6 +1125,8 @@ describe('moduleMocker', () => { testFn(); expect(mock1).toHaveBeenCalled(); + + expect.assertions(4); }); }); From 1c0d3bd46a8a476205990dc068ecabb2830e6294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Fri, 23 Sep 2022 14:40:02 +0200 Subject: [PATCH 12/14] Alphabetize changelog features --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebd150236705..84cb35b41293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,12 @@ ### Features -- `[@jest/mock]` Add `withImplementation` method for temporarily overriding a mock. - `[expect, @jest/expect]` support type inference for function parameters in `CalledWith` assertions ([#13268](https://github.com/facebook/jest/pull/13268)) - `[expect, @jest/expect]` Infer type of `*ReturnedWith` matchers argument ([#13278](https://github.com/facebook/jest/pull/13278)) - `[@jest/environment, jest-runtime]` Allow `jest.requireActual` and `jest.requireMock` to take a type argument ([#13253](https://github.com/facebook/jest/pull/13253)) - `[@jest/environment]` Allow `jest.mock` and `jest.doMock` to take a type argument ([#13254](https://github.com/facebook/jest/pull/13254)) - `[@jest/fake-timers]` Add `jest.now()` to return the current fake clock time ([#13244](https://github.com/facebook/jest/pull/13244), [13246](https://github.com/facebook/jest/pull/13246)) +- `[@jest/mock]` Add `withImplementation` method for temporarily overriding a mock. ### Fixes From 7acd442065e0f9c591b2cd3e36c28268bbe2339b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20S=C3=B8rensen?= Date: Fri, 23 Sep 2022 14:43:15 +0200 Subject: [PATCH 13/14] Add missing `)` in mock-functions type test --- packages/jest-mock/__typetests__/mock-functions.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-mock/__typetests__/mock-functions.test.ts b/packages/jest-mock/__typetests__/mock-functions.test.ts index 43c689acb64f..3d72cc4d37d0 100644 --- a/packages/jest-mock/__typetests__/mock-functions.test.ts +++ b/packages/jest-mock/__typetests__/mock-functions.test.ts @@ -255,7 +255,7 @@ expectType>( mockFn.withImplementation(mockFnImpl, async () => {}), ); -expectError(mockFn.withImplementation(mockFnImpl); +expectError(mockFn.withImplementation(mockFnImpl)); // jest.spyOn() From 51757a6c6f08f27ffc20b242806455afea99e4cb Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 23 Sep 2022 15:36:57 +0200 Subject: [PATCH 14/14] use shared isPromise helper --- packages/jest-mock/package.json | 3 ++- packages/jest-mock/src/index.ts | 8 +++----- packages/jest-mock/tsconfig.json | 2 +- yarn.lock | 1 + 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/jest-mock/package.json b/packages/jest-mock/package.json index ba0ca81eab42..bd24a84b3037 100644 --- a/packages/jest-mock/package.json +++ b/packages/jest-mock/package.json @@ -18,7 +18,8 @@ }, "dependencies": { "@jest/types": "workspace:^", - "@types/node": "*" + "@types/node": "*", + "jest-util": "workspace:^" }, "devDependencies": { "@tsd/typescript": "~4.8.2", diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index 13b61c0f1541..b727d18e749f 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -7,6 +7,8 @@ /* eslint-disable local/ban-types-eventually, local/prefer-rest-params-eventually */ +import {isPromise} from 'jest-util'; + export type MockMetadataType = | 'object' | 'array' @@ -789,11 +791,7 @@ export class ModuleMocker { const returnedValue = callback(); - if ( - returnedValue != null && - typeof returnedValue === 'object' && - typeof returnedValue.then === 'function' - ) { + if (isPromise(returnedValue)) { return returnedValue.then(() => { mockConfig.mockImpl = previousImplementation; }); diff --git a/packages/jest-mock/tsconfig.json b/packages/jest-mock/tsconfig.json index b69d4caaeea9..cf4cceccce14 100644 --- a/packages/jest-mock/tsconfig.json +++ b/packages/jest-mock/tsconfig.json @@ -6,5 +6,5 @@ }, "include": ["./src/**/*"], "exclude": ["./**/__tests__/**/*"], - "references": [{"path": "../jest-types"}] + "references": [{"path": "../jest-types"}, {"path": "../jest-util"}] } diff --git a/yarn.lock b/yarn.lock index 071ce29e6769..ecb380ee4efe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12578,6 +12578,7 @@ __metadata: "@jest/types": "workspace:^" "@tsd/typescript": ~4.8.2 "@types/node": "*" + jest-util: "workspace:^" tsd-lite: ^0.6.0 languageName: unknown linkType: soft