-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
default component args missing from importing named export stories in unit tests #14278
Comments
@tmeasday @yannbf we've addressed this in https://github.com/storybookjs/testing-react -- looks like this is also a problem inside storybook itself ... any thoughts? |
Thanks! That utility looks like a good solution to what I was seeing! Looks like I will be getting us in on the ground floor. :)
I personally don't see similar issues within storybook itself at this time so I wanted to make sure this wasn't based off something I said. Thanks for the quick response! |
Those utilities are meant for using stories inside jest where you are lacking the storybook runtime. In your case, the problem you're describing is happening inside storybook itself. Which makes me wonder whether we should be providing at least part of that utility inside Storybook core rather than as a standalone library. In the short term you can def use that library--it's great! |
Forgive me if I am misunderstanding... I just want to make sure I am not sending you down the wrong path. My issue was indeed that I was re-using stories in separate Jest unit tests and the defaults we not being applied... which it seems like this great utility provides... as far as usage in the storybook runtime environment I am seeing everything work as expected. I know there are addons that provide the ability to run tests within storybook runtime and that maybe what you are referring to but that isn't my scenario, yet :) Thanks again for the help and the great storybook work! |
Aha, thanks for the clarification -- I misunderstood. In that case, |
I am afraid I may have to take back what I said... It does look like I am seeing some similar issue within the storybook runtime if I reused predefined story components within other storybook stories. It does look like the default values are being removed. Take the following example:
MountedAd story will not have the default args.size applied and only if they are specifically defined in the BasicAd.args component props (which I have commented out in the example). Unless I am mistaken I would have expected any usage of BasicAd to have inherited the default args upon its reuse in storybook. I reserve this may not be the 100% correct pattern and that my MountedAd story should perhaps be using a decorator but I will need a story with multiple BasicAds so I would have thought this would work as desired? Thoughts? |
@shilman we should update our documentation to (at least in the react case) encourage the use of @dptoot -- there isn't really much SB can do about this one, you are literally just calling the This does seem like another argument against the import { createTemplate } from '@storybook/react';
const componentMeta = {
title: 'AdSlot',
// ...
}
export default componentMeta;
// This template knows about `componentMeta`, and also possible the global stuff too, somehow
const Template = createTemplate(componentMeta);
export const BasicAd = Template.clone(); |
Thanks for the help all. Seems like there might be a plan in place to provide this functionality and I look forward to using it :) |
Hey! I'm running into this issue with Storybook when trying to group my Doc stories into a single snapshot for Chromatic. I'm importing the stories for a particular component and then displaying them all together on a single page But running into the same issue of if the story was using Using the |
When importing named export stories into unit tests as described in the docs any defaulted component args are not retained
To Reproduce
Steps to reproduce the behavior:
My story file is as follows
and then I import it into my unit as described in the docs like so:
The resulting rendered element has the offsite arg assigned but is missing the label and href args assigned in the default export. This is not the case when storybook renders the story.
Expected behavior
I would have expected the default export args and the component args to be merged. But the args defined in the default export are missing.
System
Temp solution:
I can manually merge the named and default export args manually and assign them but that seems to default the purpose of the default args in storybook.
The text was updated successfully, but these errors were encountered: