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

[FIX] StoryShots not working for async rendered components #3677

Merged
merged 1 commit into from
Jan 31, 2022
Merged
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
21 changes: 19 additions & 2 deletions __tests__/Storyshots.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import initStoryshots from '@storybook/addon-storyshots';
import initStoryshots, { Stories2SnapsConverter } from '@storybook/addon-storyshots';
import { render } from '@testing-library/react-native';

jest.mock('rn-fetch-blob', () => ({
fs: {
Expand All @@ -19,4 +20,20 @@ jest.mock('react-native-file-viewer', () => ({
jest.mock('../app/lib/database', () => jest.fn(() => null));
global.Date.now = jest.fn(() => new Date('2019-10-10').getTime());

initStoryshots();
const converter = new Stories2SnapsConverter();

// Runner
initStoryshots({
asyncJest: true,
test: ({ story, context, done }) => {
const snapshotFilename = converter.getSnapshotFileName(context);
const storyElement = story.render();
const { update, toJSON } = render(storyElement);
update(storyElement);
setTimeout(() => {
const json = toJSON();
expect(JSON.stringify(json)).toMatchSpecificSnapshot(snapshotFilename);
done();
}, 10);
}
});
Loading