简体   繁体   中英

Using Jest for "import * as" mocking

Could you please tell how to mock this kind of import using jest?

import * as some from 'some-package';

You could try mocking like follows

jest.mock('some-package', () => ({
 // mock your methods or anything you want here, if not required leave this as is
}))

or

jest.mock('some-package');

Dont forget to use jest.unmock('some-package'); i you have other usecases

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM