Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unmount after storyshot snapshot #2417

Merged
merged 2 commits into from
Dec 3, 2017
Merged
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
19 changes: 9 additions & 10 deletions addons/storyshots/src/test-bodies.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ function getRenderedTree(story, context, { renderer, serializer, ...rendererOpti
return serializer ? serializer(tree) : tree;
}

export const snapshotWithOptions = options => ({ story, context }) => {
export const snapshotWithOptions = options => ({ story, context, snapshotFileName }) => {
const tree = getRenderedTree(story, context, options);
expect(tree).toMatchSnapshot();
};

export const multiSnapshotWithOptions = options => ({ story, context }) => {
const tree = getRenderedTree(story, context, options);
const snapshotFileName = getSnapshotFileName(context);

if (!snapshotFileName) {
if (snapshotFileName) {
expect(tree).toMatchSpecificSnapshot(snapshotFileName);
} else {
expect(tree).toMatchSnapshot();
return;
}

expect(tree).toMatchSpecificSnapshot(snapshotFileName);
tree.unmount();
};

export const multiSnapshotWithOptions = options => ({ context }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring

snapshotWithOptions({ ...options, snapshotFileName: getSnapshotFileName(context) });
};

export const snapshot = snapshotWithOptions({});
Expand Down