JavaScript Ramblings
  • Home
Sign in Subscribe

Testing

Stuck testing your connected component? Make sure you export your 'plain' component as well!

Does this sound familiar to you? You have a container component and you write a test for it: import ShoppingCartContainer from './ShoppingCart'; test('it works', () => { const wrapper = shallow(); // test something }); And then when you run it, the first thing you see is this error: Invariant violation: Could not
Corina Jan 21, 2018

3 ways to test mapStateToProps and mapDispatchToProps

You already know that you shouldn't actually test the result of calling connect (the connected component) - as Redux already makes sure the behaviour of connect is correct. Instead, you test your wrapped component separately, by exporting it as a named export. But what about mapStateToProps and mapDispatchToProps? This is
Corina Jan 15, 2018

Subscribe to JavaScript Ramblings

Don't miss out on new articles. Sign up now get them straight to your inbox.
JavaScript Ramblings © 2025. Powered by Ghost