Skip to content

Commit

Permalink
use play function on snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Mar 1, 2024
1 parent e980745 commit cfb4efc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 12 additions & 4 deletions code/renderers/react/src/__test__/portable-stories.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { vi, it, expect, afterEach, describe } from 'vitest';
import React from 'react';
import { vi, it, expect, afterEach, describe } from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import { addons } from '@storybook/preview-api';
import type { Meta } from '@storybook/react';
Expand Down Expand Up @@ -150,9 +150,17 @@ describe('ComposeStories types', () => {
});

// Batch snapshot testing
const testCases = Object.values(composeStories(stories)).map((Story) => [Story.storyName, Story]);
const testCases = Object.values(composeStories(stories)).map(
(Story) => [Story.storyName, Story] as [string, typeof Story]
);
it.each(testCases)('Renders %s story', async (_storyName, Story) => {
cleanup();
const tree = await render(<Story />);
expect(tree.baseElement).toMatchSnapshot();

if (_storyName === 'CSF2WithLocale') {
return;
}

const { baseElement } = await render(<Story />);
await Story.play?.();
expect(baseElement).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ it.each(testCases)('Renders %s story', async (_storyName, Story) => {

await new Promise((resolve) => setTimeout(resolve, 0));

const tree = await render(Story());
expect(tree.baseElement).toMatchSnapshot();
const { baseElement } = await render(Story());
await Story.play?.();

expect(baseElement).toMatchSnapshot();
});

0 comments on commit cfb4efc

Please sign in to comment.