Storybook: .addDecorator is probably not working

Created on 15 Apr 2017  路  19Comments  路  Source: storybookjs/storybook

Issue by kitze
_Friday Dec 23, 2016 at 23:37 GMT_
_Originally opened as https://github.com/storybooks/storyshots/issues/68_


I'm using material-ui in my project for some of the components. The components that are not affected by material-ui and don't need muiTheme pass the tests. But the other components that need muiTheme provided by context, are failing with a warning Warning: Failed context type: The context `muiTheme` is marked as required in `CircularProgress`, but its value is `undefined`.

Keep in mind that the stories in storybook are fine because I'm providing muiTheme through a decorator like this in my global .storybook/config.js file:

addDecorator(story => wrapWithStyles(story()));
addDecorator(story => wrapWithMui(story()));
storyshots decorators documentation help wanted merged

Most helpful comment

I can fix the repro @ktj provided with the following diff:

image

This ensures that addDecorator is called before the stories are loaded.

All 19 comments

Comment by arunoda
_Saturday Dec 24, 2016 at 00:07 GMT_


@roonyh what do you think about this issue?

Comment by roonyh
_Tuesday Dec 27, 2016 at 05:21 GMT_


@kitze I am taking a look. addDecorator works with simple wrappers but I guess something does not work with context. Have you used storyshots 2.x versions successfully with your stories?

Comment by fredantell
_Sunday Feb 26, 2017 at 17:18 GMT_


I'm running into the same issue. I have a component I specifically created for testing. I can use a global addDecorator and it works fine with storybooks. Then when I run storyshot via jest it fails trying to find functions that should have been injected via context.

If I use addDecorator on a per story level it works fine in both storybooks and storyshots.
Similarly if I just wrap each story directly in the component that also works fine for both storybook and storyshots.

Comment by jacobk
_Friday Mar 24, 2017 at 09:46 GMT_


I have this issue too with storyshots 3.2.2.

I have the same issue, Im using Styled Components and add the ThemeProvider to all the stories with the addDecorator. but the storyshots don't work when i use something like the withTheme component.

Any update on this? Using the v3

@RussMax783 can we get a reproduction of this? It sounds similar to #877, which I failed to reproduce. Would love to get a reproduction going!

Here is a reproduction:
https://github.com/ktj/storybook-rp

Run:
yarn
yarn test

Thanks @ktj that's great!

I can fix the repro @ktj provided with the following diff:

image

This ensures that addDecorator is called before the stories are loaded.

I'm guessing just moving the addDecorator line above the require.context line should work too, no?

This seems like a documentation problem more than anything. Perhaps the global addDecorator should log a warning if a story has already been registered, as this is unlikely to be what you want?

I'm guessing just moving the addDecorator line above the require.context line should work too, no?

Yup, that has the same affect. I'd be game for logging a warning: it would have saved me a ton of time debugging this.

@mattleff keen to try sending a PR?

@tmeasday Sure, I'll try to send one in the next couple days.

@shilman Can this issue be closed now?

I'll mark it merged and we'll close it when it gets released (soon!)

is it really solved?

I don't believe so. I've still been seeing the issue for material-ui components, but haven't had the time to put together an example repo, so I haven't spoken up about it yet.

yep, we faced this here https://github.com/react-theming/storybook-addon-material-ui/issues/64
maybe we can unite our efforts to solve this

i'm happy to provide details of what we are seeing and help potential solutions, but may not have time to dig into coming up with solutions at this point. happy to provide what help i can though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dnlsandiego picture dnlsandiego  路  3Comments

wahengchang picture wahengchang  路  3Comments

zvictor picture zvictor  路  3Comments

sakulstra picture sakulstra  路  3Comments

tirli picture tirli  路  3Comments