Skip to content

Commit

Permalink
refactor!: remove deprecated jest.genMockFromModule()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Apr 28, 2024
1 parent d9e64d6 commit f7de8b7
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 35 deletions.
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 f7de8b7

Please sign in to comment.