Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test higher order components? #297

Closed
ffxsam opened this issue Jul 5, 2016 · 4 comments
Closed

How to test higher order components? #297

ffxsam opened this issue Jul 5, 2016 · 4 comments

Comments

@ffxsam
Copy link

ffxsam commented Jul 5, 2016

I'm trying to use Storybook to quickly test a package of mine, which is a higher-order component:

storiesOf('Formous', module)
  .addDecorator(story => {
    return <MuiThemeProvider muiTheme={getMuiTheme()}>
      <div style={styles.root}>
        {Formous()(story())}
      </div>
    </MuiThemeProvider>
  })
  .add('normal', () => {
    //console.log(this.props);
   //...

That's not going so well :) Two questions:

  1. How do I use Storybook to test higher-order components?
  2. How do I access the props passed into the story component by Formous?
@arunoda
Copy link
Member

arunoda commented Jul 5, 2016

Here story() returns a react element. So, you need to wrap it as a class like this.

const Wrapper = () => (story());
{Formous()(Wrapper)}

@ffxsam
Copy link
Author

ffxsam commented Jul 13, 2016

Great, thanks! I'll give that a try.

@arunoda
Copy link
Member

arunoda commented Jul 14, 2016

I am closing this now. But feel free to reopen.

@arunoda arunoda closed this as completed Jul 14, 2016
@ffxsam
Copy link
Author

ffxsam commented Aug 17, 2016

This is what wound up working for me:

storiesOf('Formous', module)
  .add('basic', () => {
    const Example = ({ fields, formSubmit }) => {
      return <div>
        <form onSubmit={formSubmit(action('form submit'))}>
          <input type="text" { ...fields.name.events } />
          <input type="submit" />
        </form>
      </div>
    };
    const Wrapped = Formous(options)(Example);

    return <Wrapped />
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants