When snapshot testing (jest snapshot) a component which is connected to redux store I can export the actual component in addition to the connected component
// User.js
/* ... */
export class User extends React.Component {/* ... */}
/* ... */
export default connect(mapStateToProps)(User);
In the test file I can import the actual component (not the connected version) and do snapshot testing on it.
// User.spec.js
import { User } from './User';
/* ... toMatchSnapshot() testing */
But I run into issues when a connected component is nested inside another connected component. For example, let's say User component is nested inside another connected component -
// Wrapper.js
import User from './User'; // importing the connected version
/* ... */
export class Wrapper extends React.Component {
/* ... */
render() {
return (
<div>
/* ... */
<User />
</div>
);
}
}
export default connect(mapStateToProps)(Wrapper);
When running snapshot test on Wrapper the same way I did on User gives me the following error:
Invariant Violation: Could not find "store" in either the context or props of "Connect(User)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(User)".`
Is there any way to shallow render when snapshotting? Or am I doing something wrong?