-
-
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
Storyshots: update render w/ React.createElement #9187
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/storybook/monorepo/p7bzv1r46 |
Hmmm all my tests pass locally with only these changes and only running the |
63066a8
to
d7b6611
Compare
@tmikeschu i think at this point you just need to update snapshots
|
@shilman I had the same thought, but I don't get a diff/updates from that. I'm perplexed! |
Snapshots are updating in a kind of weird way. I think this qualifies as a breaking change, but if it seems correct we can work this into our next release, which will be 6.0. @tmikeschu @Hypnosphi please lmk what you think! |
I'm not sure what the best solution is, but let me know how I can help! @shilman where is that diff from? When I look on Circle CI, I just see a new |
@tmikeschu that's a screenshot from github desktop. there were a bunch of diffs that were all pretty similar, i just chose one at random. I suspect that this change is fine and we'll just need to wait until the next release cycle to merge it. I'm pretty sure @Hypnosphi will have an opinion, so let's see what he has to say. |
I think we can't use shallow rendering with this approach, because now we snapshot the story return value, not the one of component |
That's the case for default renderer and enzyme's
And that's the case for shallow renderers: UPD: one option is to use two-pass rendering: use the output of first shallow rendor as input for the second one // in renderShallowTree.ts
const createTwoPassRenderer = () => {
const shallowRenderer = shallow.createRenderer();
return {
render(storyElement) {
const storyOutput = shallowRenderer.render(storyElement).getRenderOutput();
return shallowRenderer.render(storyOutput);
}
}
}
function getRenderedTree(...) {
...
const shallowRenderer = renderer || createTwoPassRenderer();
...
} If users provide their own shallow renderer, they will have to implement something similar on their side |
@tmikeschu this can happen if your |
@Hypnosphi thanks for all the investigation on this. nothing's ever easy, is it? i'm not sure what a good solution is here. current solution with workaround is non-ideal, but it sure is simpler! |
Just to be clear. Current solution makes shallow storyshots test a comletely different thing, comparing to what they tested before. Given a component like that: export const MyComponent = ({someProp}) => (
<SomeOtherComponent
someImportantProp={someLogic(someProp)}
/>
) and a story like that: export const MyStory = () => <MyComponent someProp={someValue} /> Before the change, the shallow storyshot of the story would output something like that: <SomeOtherComponent
someImportantProp={valueDependingOnComponentLogic}
/> And after the change, it's
So now, instead of testing your component, you only test your story. But it's the component what you actually use in your product, and therefore want to test |
@Hypnosphi thanks for clarifying. then maybe we should do this change only for deep rendering and not for shallow rendering? |
Maybe so. By my suggestion with two-pass rendering may work as well |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
Issue: #8177
What I did
Wrapped the
story.render()
calls withReact.createElement
for storyshots.This allows you to use hooks in CSF without wrapping components in a thunk-like function.
How to test
Is this testable with Jest or Chromatic screenshots?
Jest
Does this need a new example in the kitchen sink apps?
Nope
Does this need an update to the documentation?
Nope
If your answer is yes to any of these, please make sure to include it in your PR.