import { composeStories } from '@storybook/react'; import { render } from '@testing-library/react'; import { axe } from 'jest-axe'; import * as stories from './AnnouncementBanner.stories'; const testCases = Object.values(composeStories(stories)).map((Story) => [Story.storyName || 'Story', Story]); test.each(testCases)(`renders %s without crashing`, async (_storyname, Story) => { const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); test.each(testCases)('%s should have no a11y violations', async (_storyname, Story) => { const { container } = render(); /** ** We are disabling the rule in this case because ideally we should not have nested interactive ** but in this case we need to open a modal when clicking in the `AnnouncementBanner` **/ const results = await axe(container, { rules: { 'nested-interactive': { enabled: false } } }); expect(results).toHaveNoViolations(); });