mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-20 05:02:37 +08:00
Merge pull request #3479 from wuweiweiwu/issue-3026
feat: add renderWithOptions to @addons/storyshots
This commit is contained in:
commit
c2887f5617
@ -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.
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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({});
|
||||
|
@ -0,0 +1,8 @@
|
||||
import path from 'path';
|
||||
import initStoryshots, { renderWithOptions } from '../src';
|
||||
|
||||
initStoryshots({
|
||||
framework: 'react',
|
||||
configPath: path.join(__dirname, '..', '.storybook'),
|
||||
test: renderWithOptions({}),
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user