Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@jest/globals): add missing options argument to jest.doMock typing #12292

Merged
merged 3 commits into from Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,9 +4,10 @@

### Fixes

- `[matcher-utils]` Correct diff for expected asymmetric matchers ([#12264](https://github.com/facebook/jest/pull/12264))
- `[expect]` Add a fix for `.toHaveProperty('')` ([#12251](https://github.com/facebook/jest/pull/12251))
- `[@jest/globals]` Add missing `options` argument to `jest.doMock` typing ([#12292](https://github.com/facebook/jest/pull/12292))
- `[jest-environment-node]` Add `atob` and `btoa` ([#12269](https://github.com/facebook/jest/pull/12269))
- `[jest-matcher-utils]` Correct diff for expected asymmetric matchers ([#12264](https://github.com/facebook/jest/pull/12264))
- `[jest-message-util]` Fix `.getTopFrame()` (and `toMatchInlineSnapshot()`) with `mjs` files ([#12277](https://github.com/facebook/jest/pull/12277))

### Chore & Maintenance
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-environment/src/index.ts
Expand Up @@ -92,7 +92,11 @@ export interface Jest {
* the top of the code block. Use this method if you want to explicitly avoid
* this behavior.
*/
doMock(moduleName: string, moduleFactory?: () => unknown): Jest;
doMock(
moduleName: string,
moduleFactory?: () => unknown,
options?: {virtual?: boolean},
): Jest;
/**
* Indicates that the module system should never return a mocked version
* of the specified module from require() (e.g. that it should always return
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-types/__typechecks__/jest.test.ts
Expand Up @@ -20,9 +20,8 @@ expectType<typeof jest>(jest.deepUnmock('moduleName'));
expectType<typeof jest>(jest.disableAutomock());
expectType<typeof jest>(jest.doMock('moduleName'));
expectType<typeof jest>(jest.doMock('moduleName', jest.fn()));

expectError(jest.doMock('moduleName', jest.fn(), {}));
expectError(jest.doMock('moduleName', jest.fn(), {virtual: true}));
expectType<typeof jest>(jest.doMock('moduleName', jest.fn(), {}));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange to allow empty object, but jest.mock is typed exactly the same.

expectType<typeof jest>(jest.doMock('moduleName', jest.fn(), {virtual: true}));

expectType<typeof jest>(jest.dontMock('moduleName'));
expectType<typeof jest>(jest.enableAutomock());
Expand Down