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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual mocks cannot be unmocked #8395

Closed
Blasz opened this issue Apr 30, 2019 · 1 comment 路 Fixed by #8396
Closed

Virtual mocks cannot be unmocked #8395

Blasz opened this issue Apr 30, 2019 · 1 comment 路 Fixed by #8396

Comments

@Blasz
Copy link
Contributor

Blasz commented Apr 30, 2019

馃悰 Bug Report

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:

  1. Call jest.doMock('abc', () => ({ foo: jest.fn() }), { virtual: true }); in one test.
  2. Call jest.dontMock('abc'); in a subsequent test.
  3. 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.

Link to repl or repo (highly encouraged)

https://repl.it/repls/AjarIdealConfig

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS Mojave 10.14.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 10.9.0 - ~/.nvm/versions/node/v10.9.0/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.2.0 - ~/.nvm/versions/node/v10.9.0/bin/npm
  npmPackages:
    jest: ^24.4.0 => 24.4.0
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant