I have a React component which contains some other components that depend on access to a Redux store etc., which cause issues when doing a full Enzyme mount. Let\'s say a st
There's a note at the bottom of the docs for jest.mock() for preventing the hoisting behavior:
Note: When using
babel-jest
, calls tomock
will automatically be hoisted to the top of the code block. UsedoMock
if you want to explicitly avoid this behavior.
Then you can do as you described: return a function that is a stub of the component you don't need to test.
jest.doMock('./ComponentToMock', () => {
const ComponentToMock = () => ;
return ComponentToMock;
});
const ComponentToTest = require('./ComponentToTest').default;
It's helpful to name the stub component since it gets rendered in snapshots.