You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After a virtual mock has been created via jest.doMock(..., ..., { virtual: true }) cannot be unmocked via jest.dontMock(...).
The use case for this is when I am testing a module that dynamically requires another module. I have created a virtual mock to test this functionality but want to unmock it in the same test suite so that I can test the error state when the module does not exist.
To Reproduce
Steps to reproduce the behavior:
Call jest.doMock('abc', () => ({ foo: jest.fn() }), { virtual: true }); in one test.
Call jest.dontMock('abc'); in a subsequent test.
Call require('abc') and observe that it returns the virtual mock still
Expected behavior
The virtual mock should not exist anymore and the require call should throw an error.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
🐛 Bug Report
After a virtual mock has been created via
jest.doMock(..., ..., { virtual: true })
cannot be unmocked viajest.dontMock(...)
.The use case for this is when I am testing a module that dynamically requires another module. I have created a virtual mock to test this functionality but want to unmock it in the same test suite so that I can test the error state when the module does not exist.
To Reproduce
Steps to reproduce the behavior:
jest.doMock('abc', () => ({ foo: jest.fn() }), { virtual: true });
in one test.jest.dontMock('abc');
in a subsequent test.require('abc')
and observe that it returns the virtual mock stillExpected behavior
The virtual mock should not exist anymore and the
require
call should throw an error.Link to repl or repo (highly encouraged)
https://repl.it/repls/AjarIdealConfig
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: