Skip to content

Commit

Permalink
Allow passing options to react-test-renderer .create() method
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdrg authored and John Rodriguez committed Apr 17, 2017
1 parent 930c08a commit 43eb312
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/storyshots/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function testStorySnapshots(options = {}) {
it(story.name, () => {
const context = { kind: group.kind, story: story.name };
const renderedStory = story.render(context);
const tree = renderer.create(renderedStory).toJSON();
const tree = renderer.create(renderedStory, options.rendererOptions).toJSON();
expect(tree).toMatchSnapshot();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ exports[`Storyshots Button with text 1`] = `
</button>
`;

exports[`Storyshots Component with ref on mount 1`] = `
<input
style={
Object {
"backgroundColor": "#FFFFFF",
"border": "1px solid #eee",
"borderRadius": 3,
"fontSize": 15,
"margin": 10,
"padding": "3px 10px",
"width": "400px",
}
}
type="text"
value="This component reads its scrollWidth on load." />
`;

exports[`Storyshots Welcome to Storybook 1`] = `
<div
style={
Expand Down
10 changes: 9 additions & 1 deletion packages/storyshots/stories/__test__/storyshots.test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
import initStoryshots from '../../src';
initStoryshots();

function createNodeMock (element) {
if (element.type === 'input') {
return { scrollWidth: 123 };
}
return null;
}

initStoryshots({ rendererOptions: { createNodeMock } });
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import PropTypes from 'prop-types';
import React from 'react';

const inputStyles = {
border: '1px solid #eee',
borderRadius: 3,
backgroundColor: '#FFFFFF',
fontSize: 15,
padding: '3px 10px',
margin: 10,
width: '400px'
};

class ComponentWithRef extends React.Component {
componentDidMount () {
this.props.onLoad('scrollWidth: ' + this.ref.scrollWidth);
}
setRef (ref) {
this.ref = ref;
}
render () {
return (
<input
type='text'
value={'This component reads its scrollWidth on load.'}
ref={r => this.setRef(r)}
style={inputStyles}
/>
);
}
}

ComponentWithRef.propTypes = {
onLoad: PropTypes.func
};

export default ComponentWithRef;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import { storiesOf, action } from '@kadira/storybook';
import ComponentWithRef from './ComponentWithRef';

storiesOf('Component with ref', module)
.add('on mount', () => (
<ComponentWithRef onLoad={action('component mount')} />
));

0 comments on commit 43eb312

Please sign in to comment.