- src/testUtils.tsx: used to handle global tests configuration, as providing the wrappers that will be used to all tests.
This project is using Storybook stories to be used as the arranged component (first "A" of AAA). The library @storybook/testing-react provides methods to import components stories so that you write once and use twice. For example, the Post.spec.tsx file imported stories from Post.stories.tsx and assert using the story args:
import * as React from 'react';
import { composeStories } from '@storybook/testing-react';
import { render, screen } from '../../testUtils';
import * as stories from './Post.stories';
const { Example } = composeStories(stories);
test('testing post content', () => {
render(<Example />);
expect(screen.getByText(Example.args?.content)).toBeInTheDocument();
});To confirm that this test is not a false positive, change the assertion to
expect(screen.getByText(Example.args?.content + 'a')).toBeInTheDocument();and execute yarn test.