Last active
February 22, 2022 16:40
-
-
Save Itsindigo/0e2191720b0b106b39ffd02853c5cdd7 to your computer and use it in GitHub Desktop.
How to partially mock a module with jest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { functionWithDependencyThatNeedsMocking } from './service'; | |
jest.mock('./service', () => { | |
...jest.requireActual('./service'); | |
dependencyThatNeedsMocking: jest.fn() | |
}) | |
it('should mock the call', () => { | |
const mySpy = jest.spyOn('./service', 'dependencyThatNeedsMocking') | |
functionWithDependencyThatNeedsMocking() | |
expect(mySpy).toHaveCallCount(1) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment