diff --git a/addons/storyshots/README.md b/addons/storyshots/README.md index d920613b7008..6a707774ccf9 100644 --- a/addons/storyshots/README.md +++ b/addons/storyshots/README.md @@ -116,3 +116,8 @@ The default, render the story as normal and take a Jest snapshot. ### `renderOnly` Just render the story, don't check the output at all (useful if you just want to ensure it doesn't error). + + +### `snapshotWithOptions(options)` + +Like the default, but allows you to specify a set of options for the test renderer. See for example: https://github.com/storybooks/storybook/blob/b915b5439786e0edb17d7f5ab404bba9f7919381/examples/test-cra/src/storyshots.test.js#L14-L16 diff --git a/addons/storyshots/src/index.js b/addons/storyshots/src/index.js index 2a6f80c20702..6c5f9ab39bce 100644 --- a/addons/storyshots/src/index.js +++ b/addons/storyshots/src/index.js @@ -6,7 +6,7 @@ import createChannel from './storybook-channel-mock'; import { snapshot } from './test-bodies'; const { describe, it, expect } = global; -export { snapshot, renderOnly } from './test-bodies'; +export { snapshotWithOptions, snapshot, renderOnly } from './test-bodies'; let storybook; let configPath; diff --git a/addons/storyshots/src/test-bodies.js b/addons/storyshots/src/test-bodies.js index 0da64358a671..2f7bfb694ae4 100644 --- a/addons/storyshots/src/test-bodies.js +++ b/addons/storyshots/src/test-bodies.js @@ -1,11 +1,13 @@ import renderer from 'react-test-renderer'; import shallow from 'react-test-renderer/shallow'; -export function snapshot({ story, context }) { +export const snapshotWithOptions = options => ({ story, context }) => { const storyElement = story.render(context); - const tree = renderer.create(storyElement).toJSON(); + const tree = renderer.create(storyElement, options).toJSON(); expect(tree).toMatchSnapshot(); -} +}; + +export const snapshot = snapshotWithOptions({}); export function renderOnly({ story, context }) { const storyElement = story.render(context); diff --git a/examples/test-cra/src/__snapshots__/storyshots.test.js.snap b/examples/test-cra/src/__snapshots__/storyshots.test.js.snap index 175d0e1be3a0..572220639b8c 100644 --- a/examples/test-cra/src/__snapshots__/storyshots.test.js.snap +++ b/examples/test-cra/src/__snapshots__/storyshots.test.js.snap @@ -38,6 +38,8 @@ exports[`Storyshots Button with text 1`] = ` `; +exports[`Storyshots ComponentWithRef basic 1`] = `
`; + exports[`Storyshots Welcome to Storybook 1`] = `