question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Is it valid to test Redux-Form components?

See original GitHub issue

I’m having a little trouble when I try to test a Redux-Form component in the storybook. The error I get is Uncaught Invariant Violation: Could not find "store" in either the context or props of "Connect(ReduxForm(SimpleForm))". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(ReduxForm(SimpleForm))".

Which I imagine is because there’s no <Provider store={store}> wrapping the storybook root. What I first want to check is if this is a valid use case for the story book, and if so, what the suggested best approach would be for getting redux-form to play nice in the storybook.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
faceyspaceycommented, Sep 27, 2016

also if anyone is having issues with the redux provider not being able to hot load, put it in another file than your config.js file like this:

config.js:

import Provider from './Provider';

addDecorator((story) => {
  return <Provider story={story()} />;
});

Provider.js:

import React from 'react';
import {Provider as ReduxProvider} from 'react-redux';
import configureStore from '../app/configureStore';

let store = configureStore();

export default function Provider({story}) {
  return (
    <ReduxProvider store={store}>
        {story}
    </ReduxProvider>
  );
};

That way when your config.js file hot reloads it doesn’t have to hot reload your redux Provider “on the fly.”

3reactions
c-crosbycommented, Dec 10, 2017

for those getting React.Children.only you can wrap your provider output in a div to address the issue

<div>{story}</div>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing reduxForm component methods with jest and enzyme
I'm testing a reduxForm component with jest and enzyme and I don't know how i can test methods within this component.
Read more >
Unit and Integration Testing of React/Redux Forms
Testing is an important part of any development process, but no single test will give you all the answers you need.
Read more >
Field-Level Validation Example - Redux Form
If the value is valid, the validation function should return undefined . If the value is invalid, the validation function should return an...
Read more >
Managing Form State in React With Redux Form - DigitalOcean
redux-form has the following components to help you build your ... we check if it's empty and also check if it's a valid...
Read more >
Testing React Components with Jest and Enzyme- In Depth
Don't take for testing, for example, 'array' field, if you are not sure how to test 'text' field; don't take components decorated with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found