enzyme: Not able to get to actions via props() via shallow
prior to redux 7:
it('contains expected actions', () => {
const homePage = shallow(<HomePageContainer store={store} />);
expect(homePage.props().fetchFeaturedCompanies).to.exist;
expect(homePage.props().fetchCompanies).to.exist;
});
after Redux 7 I don’t think you can just pass in store as a prop anymore. I thought that they added back that ability? I don’t remember where they landed with that.
So since I was getting an error that store is not a property, I had to wrap this in a garbage provider to even get this to compile again after upgrading Redux:
But after doing so, TS complains that store is not a prop:
it('contains expected actions', () => {
const homePage = shallow(<Provider store={store}><HomePageContainer /></Provider>);
expect(homePage.props().fetchFeaturedCompanies).to.exist;
expect(homePage.props().fetchCompanies).to.exist;
});
expected undefined to exist
Here’s yet another old test that tries to get to an action via props
it('fetches companies', async () => {
mockGet('/api/v1/companies', {});
const homePage = shallow(<HomePageContainer store={store} />);
await homePage.props().fetchCompanies();
const newState = store.getState();
expect(newState.company.companies).to.exist;
expect(newState.company.featuredCompanies).to.not.exist;
});
so it no longer is able to get at props this way or something after Redux 7?
Sigh it’s been a while, totally forgot this thread https://github.com/reduxjs/react-redux/issues/1161
can anyone fill me in on the above, if this is even possible in Redux 7 both sending in a store as a prop and also being able to access actions like this as my existing tests were doing with props()?
My preference is:
- not to go through UI wiring like button clicks
- not to use mount
I like testing the surface area via props.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (5 by maintainers)
enzyme - like all runtime javascript code - doesn’t know about, see, or care about type notations. Adding anything in type-space should have no impact on value-space.
Glad you found a fix.