Last active
September 17, 2022 12:34
-
-
Save dongyuwei/8475f39e6a0b71dacb6dd75bdbfcdc28 to your computer and use it in GitHub Desktop.
mock a default export function in another module
This file contains 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
jest.mock('../utilities/prompt/prompt', () => { | |
const originalModule = jest.requireActual('../utilities/prompt/prompt'); | |
return { | |
__esModule: true, | |
...originalModule, | |
default: jest.fn((args)=> { | |
if(args.onConfirm){ | |
args.onConfirm('lost reason') | |
} | |
}), | |
}; | |
}); | |
// then if you call prompt({onConfirm: callback}), test will callback function. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment