Last active
December 5, 2022 15:14
-
-
Save axelnormand/df3399b891fbfe55860a4c8bca37a8f0 to your computer and use it in GitHub Desktop.
React Native Storybook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////// | |
// AUTO GENERATED by createTests.ts | |
// This is the storyshot for the story file | |
// One test file per story to help test watching | |
/////////////////// | |
import { getSnapshotFileName } from '@storybook/addon-storyshots'; | |
import { shallow } from 'enzyme'; | |
import toJson from 'enzyme-to-json'; | |
import React from 'react'; | |
// run setupSnapshotTest to mock things | |
import 'src/test/storybook/storyshots/setupSnapshotTest'; | |
const { configure, getStorybook } = require('@storybook/react-native'); | |
// setup storybook for this story. [Replace require when generating test] | |
configure(() => { | |
require('./testStory'); | |
}, module); | |
// read file and create test per story | |
const stories = getStorybook(); | |
if (stories.length === 0) { | |
throw new Error('Found 0 stories'); | |
} | |
for (const group of stories) { | |
const { fileName, kind } = group; | |
describe(kind, () => { | |
for (const story of group.stories) { | |
const context = { | |
fileName, | |
kind, | |
story: story.name, | |
framework: 'react-native', | |
}; | |
test(story.name, () => { | |
const snapshotFileName = getSnapshotFileName(context); | |
if (snapshotFileName) { | |
const storyElement = story.render(context) as React.ReactElement<any>; | |
// shallow render for snapshot | |
const wrapper = shallow(storyElement); | |
const ret = toJson(wrapper); | |
// @ts-ignore toMatchSpecificSnapshot patched by storyshots | |
expect(ret).toMatchSpecificSnapshot(snapshotFileName); | |
} | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment