-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support unstable_unmockModule (#15080)
- Loading branch information
1 parent
d65d4cc
commit 9c9ce8a
Showing
9 changed files
with
140 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import {jest as jestObject} from '@jest/globals'; | ||
|
||
afterEach(() => { | ||
jestObject.resetModules(); | ||
}); | ||
|
||
test('can mock module', async () => { | ||
jestObject.unstable_mockModule('../mockedModule.mjs', () => ({foo: 'bar'}), { | ||
virtual: true, | ||
}); | ||
|
||
const importedMock = await import('../mockedModule.mjs'); | ||
|
||
expect(Object.keys(importedMock)).toEqual(['foo']); | ||
expect(importedMock.foo).toBe('bar'); | ||
}); | ||
|
||
test('can mock transitive module', async () => { | ||
jestObject.unstable_mockModule('../index.js', () => ({foo: 'bar'})); | ||
|
||
const importedMock = await import('../reexport.js'); | ||
|
||
expect(Object.keys(importedMock)).toEqual(['foo']); | ||
expect(importedMock.foo).toBe('bar'); | ||
}); | ||
|
||
test('can unmock module', async () => { | ||
jestObject.unstable_mockModule('../index.js', () => ({ | ||
double: () => 1000, | ||
})); | ||
|
||
const importedMock = await import('../index.js'); | ||
expect(importedMock.double()).toBe(1000); | ||
|
||
jestObject.unstable_unmockModule('../index.js'); | ||
|
||
const importedMockAfterUnmock = await import('../index.js'); | ||
expect(importedMockAfterUnmock.double(2)).toBe(4); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters