-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Test renderer options #1085
Test renderer options #1085
Conversation
# Conflicts: # .jestrc.json # addons/storyshots/src/index.js
@tmeasday Can you review and test this? |
Hey @ndelangen
import initStoryshots from '@storybooks/addon-storyshots';
import renderer from 'react-test-renderer';
const createNodeMock = () => {
// ...
]
initStoryShots({
test({ story, context }) {
const storyElement = story.render(context, { createNodeMock });
const tree = renderer.create(storyElement).toJSON();
expect(tree).toMatchSnapshot();
}
}); @jrdrg -- I wonder if the above works for you with the latest alpha?
|
Perhaps the |
I think this can be closed as it's superceded by #1090 |
This PR replaces: #896
Issue:
When running storyshots with a story for a component that uses refs, it will throw a null reference error (see facebook/react#7371)
What I did
This PR adds the ability to pass options to the react-test-renderer create method, for example to allow mocking refs as per https://facebook.github.io/react/blog/2016/11/16/react-v15.4.0.html#mocking-refs-for-snapshot-testing
How to test
Run
yarn test
-ComponentWithRef.stories.js
should use thecreateNodeMock
function defined instoryshots.test.js
to mock its ref and not fail with a null reference error. The story forComponentWithRef
attempts to get the scrollWidth of a div when the component mounts.