I'm trying to figure out how to correctly mock the @mailchimp/mailchimp_transactional
npm module in my tests.
I'm getting caught up in how it shows to import mailchimp from the documentation, with an immediate call to the constructor with the API key
const mailchimp = require('@mailchimp/mailchimp_transactional')(API_KEY);
According to the Jest documentation, I'd normally mock it with something like
jest.mock('@mailchimp/mailchimp_transactional');
But I'm not sure how to then create the instance with a fake API key? I keep getting an undefined result from trying to call the mocked version of mailchimp
. Would I need to mock a constructor()
function as well?
I think it should be something like this:
jest.mock(
'@mailchimp/mailchimp_transactional',
() => API_KEY => ({ object that mocks mailchimp })
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.