Skip to content

Jest: How to undo a global mock for certain tests in a file

I want to mock Math.random for certain tests and use its original implementation for other tests. How can I achieve this? I’ve read about using jest.doMock and jest.dontMock, but I’ve bumped into a number of issues using them, like: I seem to need require in order to use doMock and dontMock, but m…