Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Allow passing options to react-test-renderer .create() method #76

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,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
17 changes: 17 additions & 0 deletions stories/__test__/__snapshots__/storyshots.test.js.snap
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 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 } })
36 changes: 36 additions & 0 deletions stories/required_with_context/ComponentWithRef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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: React.PropTypes.func
}

export default ComponentWithRef
8 changes: 8 additions & 0 deletions stories/required_with_context/ComponentWithRef.stories.js
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')} />
))