Merge pull request #3479 from wuweiweiwu/issue-3026

feat: add renderWithOptions to @addons/storyshots
This commit is contained in:
Wei-Wei Wu 2018-05-29 00:06:54 -07:00 committed by GitHub
commit c2887f5617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 19 deletions

View File

@ -426,12 +426,16 @@ 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).
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 here](https://github.com/storybooks/storybook/blob/b915b5439786e0edb17d7f5ab404bba9f7919381/examples/test-cra/src/storyshots.test.js#L14-L16).
### `renderWithOptions(options)`
Like the default, but allows you to specify a set of options for the renderer. See above.
### `multiSnapshotWithOptions(options)`
Like `snapshotWithOptions`, but generate a separate snapshot file for each stories file rather than a single monolithic file (as is the convention in Jest). This makes it dramatically easier to review changes. If you'd like the benefit of separate snapshot files, but don't have custom options to pass, simply pass an empty object.

View File

@ -13,6 +13,7 @@ import {
snapshot,
shallowSnapshot,
renderOnly,
renderWithOptions,
} from './test-bodies';
global.STORYBOOK_REACT_CLASSES = global.STORYBOOK_REACT_CLASSES || {};
@ -24,6 +25,7 @@ export {
snapshotWithOptions,
shallowSnapshot,
renderOnly,
renderWithOptions,
imageSnapshot,
};

View File

@ -41,14 +41,16 @@ export function shallowSnapshot({ story, context, renderShallowTree, options = {
expect(result).toMatchSnapshot();
}
export function renderOnly({ story, context, renderTree }) {
const result = renderTree(story, context, {});
export const renderWithOptions = options => ({ story, context, renderTree }) => {
const result = renderTree(story, context, options);
if (typeof result.then === 'function') {
return result;
}
return undefined;
}
};
export const renderOnly = renderWithOptions({});
export const snapshot = snapshotWithOptions({});

View File

@ -0,0 +1,8 @@
import path from 'path';
import initStoryshots, { renderWithOptions } from '../src';
initStoryshots({
framework: 'react',
configPath: path.join(__dirname, '..', '.storybook'),
test: renderWithOptions({}),
});