Skip to content

Commit 1bf56dd

Browse files
authored
refactor!: remove deprecated jest.genMockFromModule() (#15042)
1 parent d9e64d6 commit 1bf56dd

File tree

5 files changed

+2
-35
lines changed

5 files changed

+2
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- `[@jest/core]` [**BREAKING**] Changed `--filter` to accept an object with shape `{ filtered: Array<string> }` to match [documentation](https://jestjs.io/docs/cli#--filterfile) ([#13319](https://github.com/jestjs/jest/pull/13319))
1616
- `[@jest/core]` Support `--outputFile` option for [`--listTests`](https://jestjs.io/docs/cli#--listtests) ([#14980](https://github.com/jestjs/jest/pull/14980))
1717
- `[@jest/core, @jest/test-sequencer]` [**BREAKING**] Exposes `globalConfig` & `contexts` to `TestSequencer` ([#14535](https://github.com/jestjs/jest/pull/14535), & [#14543](https://github.com/jestjs/jest/pull/14543))
18+
- `[@jest/environment]` [**BREAKING**] Remove deprecated `jest.genMockFromModule()` ([#15042](https://github.com/jestjs/jest/pull/15042))
1819
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825))
1920
- `[@jest/environment-jsdom-abstract]` Introduce new package which abstracts over the `jsdom` environment, allowing usage of custom versions of JSDOM ([#14717](https://github.com/jestjs/jest/pull/14717))
2021
- `[jest-environment-node]` Update jest environment with dispose symbols `Symbol` ([#14888](https://github.com/jestjs/jest/pull/14888) & [#14909](https://github.com/jestjs/jest/pull/14909))

packages/jest-environment/src/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,6 @@ export interface Jest {
153153
* Creates a mock function. Optionally takes a mock implementation.
154154
*/
155155
fn: ModuleMocker['fn'];
156-
// TODO remove `genMockFromModule()` in Jest 30
157-
/**
158-
* Given the name of a module, use the automatic mocking system to generate a
159-
* mocked version of the module for you.
160-
*
161-
* This is useful when you want to create a manual mock that extends the
162-
* automatic mock's behavior.
163-
*
164-
* @deprecated Use `jest.createMockFromModule()` instead
165-
*/
166-
genMockFromModule<T = unknown>(moduleName: string): Mocked<T>;
167156
/**
168157
* When mocking time, `Date.now()` will also be mocked. If you for some reason
169158
* need access to the real current time, you can invoke this function.

packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,28 +231,6 @@ describe('dependencyExtractor', () => {
231231
);
232232
});
233233

234-
it('should extract dependencies from `jest.genMockFromModule` calls', () => {
235-
const code = `
236-
// Good
237-
jest.genMockFromModule('dep1');
238-
const dep2 = jest.genMockFromModule(
239-
"dep2",
240-
);
241-
if (jest.genMockFromModule(\`dep3\`).cond) {}
242-
jest
243-
.requireMock('dep4');
244-
245-
// Bad
246-
foo . jest.genMockFromModule('inv1')
247-
xjest.genMockFromModule('inv2');
248-
jest.genMockFromModulex('inv3');
249-
jest.genMockFromModule('inv4', 'inv5');
250-
`;
251-
expect(extractor.extract(code)).toEqual(
252-
new Set(['dep1', 'dep2', 'dep3', 'dep4']),
253-
);
254-
});
255-
256234
it('should extract dependencies from `jest.createMockFromModule` calls', () => {
257235
const code = `
258236
// Good

packages/jest-haste-map/src/lib/dependencyExtractor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const IMPORT_OR_EXPORT_RE = createRegExp(
6060
const JEST_EXTENSIONS_RE = createRegExp(
6161
[
6262
...functionCallStart(
63-
'jest\\s*\\.\\s*(?:requireActual|requireMock|genMockFromModule|createMockFromModule)',
63+
'jest\\s*\\.\\s*(?:requireActual|requireMock|createMockFromModule)',
6464
),
6565
CAPTURE_STRING_LITERAL(1),
6666
WHITESPACE,

packages/jest-runtime/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,6 @@ export default class Runtime {
23592359
dontMock: unmock,
23602360
enableAutomock,
23612361
fn,
2362-
genMockFromModule: moduleName => this._generateMock(from, moduleName),
23632362
getRealSystemTime: () => {
23642363
const fakeTimers = _getFakeTimers();
23652364

0 commit comments

Comments
 (0)