Skip to content

Instantly share code, notes, and snippets.

@dongyuwei
Last active September 17, 2022 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongyuwei/8475f39e6a0b71dacb6dd75bdbfcdc28 to your computer and use it in GitHub Desktop.
Save dongyuwei/8475f39e6a0b71dacb6dd75bdbfcdc28 to your computer and use it in GitHub Desktop.
mock a default export function in another module
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