Ever tried to mock a primitive? You can create a mock within your test file...
...but that only works once. If you need to test variations of that, you need to make a new test file for each version.
Unless you use
To mock primitives on a file called
config.js, add a manual
mock. Then export
the module after passing it through
// __mocks__/config.js// Use module.exports and provide the absolute path.moduleexports =
Now you can mock primitives just like you mock functions. Each primitive is on
the mocked module with the original value, but they also have "backdoor" mocks.
To alter or interrogate the mock for
The rest of the module is mocked via genMockFromModule, so you can use it as usual.
Due to the way the
import * as style of imports breaks
this does not work without a minor tweak.
For any non-functions you want to mock, the call sites must reference the
default export as shown here.
// can't mock// export const getName = () => config.name// can mockconst getName = configdefaultname
kickstarted by npm-boom