unit testing - Jest Mocking node_modules With Nested File -
i trying mock 3rd party library (in node_modules) nested in sub-directory. have created mock in __mocks__/@exponent/ex-navigation
. sits @ top level next node_modules dir.
i setup mock within test file via jest.mock('@exponent/ex-navigation');
.
for reason can't use mock file. think has @exponent
subdirectory. if change simple fs
works.
it appears jest not support mocking scoped packages (more info here). have 2 options.
1. define mock inline
jest.mock('@exponent/ex-navigation', () => { return { // mocked exports }; });
2. manually map mock location in jest config
{ ... "modulenamemapper": [ "@exponent/ex-navigation": "<rootdir>/__mocks__/@exponent/ex-navigation" ... ] }
Comments
Post a Comment