storybook/docs/snippets/common/portable-stories-vitest-multi-snapshot-test.js.mdx
2024-01-09 15:21:46 +01:00

30 lines
820 B
Plaintext

```ts
// storybook.test.js|ts
// ...Code omitted for brevity
describe(options.suite, () => {
// 👇 Add storyDir in the arguments list
getAllStoryFiles().forEach(({ filePath, storyFile, storyDir }) => {
// ...Previously existing code
describe(title, () => {
// ...Previously existing code
stories.forEach(({ name, story }) => {
// ...Previously existing code
testFn(name, async () => {
// ...Previously existing code
// 👇 Define the path to save the snapshot to:
const snapshotPath = path.join(
storyDir,
options.snapshotsDirName,
`${componentName}${options.snapshotExtension}`,
);
expect(mounted.container).toMatchFileSnapshot(snapshotPath);
});
});
});
});
});
```