Skip to content

Commit

Permalink
refactor!: remove deprecated jest.genMockFromModule() (#15042)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Apr 29, 2024
1 parent d9e64d6 commit 1bf56dd
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- `[@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))
- `[@jest/core]` Support `--outputFile` option for [`--listTests`](https://jestjs.io/docs/cli#--listtests) ([#14980](https://github.com/jestjs/jest/pull/14980))
- `[@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))
- `[@jest/environment]` [**BREAKING**] Remove deprecated `jest.genMockFromModule()` ([#15042](https://github.com/jestjs/jest/pull/15042))
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825))
- `[@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))
- `[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))
Expand Down
11 changes: 0 additions & 11 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,6 @@ export interface Jest {
* Creates a mock function. Optionally takes a mock implementation.
*/
fn: ModuleMocker['fn'];
// TODO remove `genMockFromModule()` in Jest 30
/**
* Given the name of a module, use the automatic mocking system to generate a
* mocked version of the module for you.
*
* This is useful when you want to create a manual mock that extends the
* automatic mock's behavior.
*
* @deprecated Use `jest.createMockFromModule()` instead
*/
genMockFromModule<T = unknown>(moduleName: string): Mocked<T>;
/**
* When mocking time, `Date.now()` will also be mocked. If you for some reason
* need access to the real current time, you can invoke this function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,28 +231,6 @@ describe('dependencyExtractor', () => {
);
});

it('should extract dependencies from `jest.genMockFromModule` calls', () => {
const code = `
// Good
jest.genMockFromModule('dep1');
const dep2 = jest.genMockFromModule(
"dep2",
);
if (jest.genMockFromModule(\`dep3\`).cond) {}
jest
.requireMock('dep4');
// Bad
foo . jest.genMockFromModule('inv1')
xjest.genMockFromModule('inv2');
jest.genMockFromModulex('inv3');
jest.genMockFromModule('inv4', 'inv5');
`;
expect(extractor.extract(code)).toEqual(
new Set(['dep1', 'dep2', 'dep3', 'dep4']),
);
});

it('should extract dependencies from `jest.createMockFromModule` calls', () => {
const code = `
// Good
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/lib/dependencyExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const IMPORT_OR_EXPORT_RE = createRegExp(
const JEST_EXTENSIONS_RE = createRegExp(
[
...functionCallStart(
'jest\\s*\\.\\s*(?:requireActual|requireMock|genMockFromModule|createMockFromModule)',
'jest\\s*\\.\\s*(?:requireActual|requireMock|createMockFromModule)',
),
CAPTURE_STRING_LITERAL(1),
WHITESPACE,
Expand Down
1 change: 0 additions & 1 deletion packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,6 @@ export default class Runtime {
dontMock: unmock,
enableAutomock,
fn,
genMockFromModule: moduleName => this._generateMock(from, moduleName),
getRealSystemTime: () => {
const fakeTimers = _getFakeTimers();

Expand Down

0 comments on commit 1bf56dd

Please sign in to comment.