We've released the Enterprise CLI for seamless deployments of Next.js projects on the AWS with complete IaC (Terraform) setup. Learn more
Blazity Logo
Development

Automated testing

Overview of the testing tools available in the project

This boilerplate comes with various testing setups to ensure your application's reliability and robustness.

main.ts
preview.ts
playwright.yml
Button.stories.tsx
jest.config.js
jest.setup.js
example.spec.ts
playwright.config.ts

Unit & Integration Testing

Jest is a popular and battle-tested library created by Meta used for unit and integration testing by millions of developers.

Run pnpm run test to run the tests.

Refer to the Predefined Scripts file for more information on the available scripts.

End-to-End Testing

Playwright is used for end-to-end testing.

  • Run pnpm run e2e:headless to run the tests in headless mode.
  • Run pnpm run e2e:ui to run the tests in UI mode.

Refer to the Predefined Scripts file for more information on the available scripts.

Acceptance Testing

To write acceptance tests, we leverage Storybook's play function. This allows you to interact with your components and test various user flows within Storybook.

/*
 * See https://storybook.js.org/docs/react/writing-stories/play-function#working-with-the-canvas
 * to learn more about using the canvasElement to query the DOM
 */
export const FilledForm: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
 
    const emailInput = canvas.getByLabelText("email", {
      selector: "input",
    });
 
    await userEvent.type(emailInput, "example-email@email.com", {
      delay: 100,
    });
 
    const passwordInput = canvas.getByLabelText("password", {
      selector: "input",
    });
 
    await userEvent.type(passwordInput, "ExamplePassword", {
      delay: 100,
    });
    // See https://storybook.js.org/docs/react/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
    const submitButton = canvas.getByRole("button");
 
    await userEvent.click(submitButton);
  },
};

Smoke Testing

In this boilerplate, we use Storybook's out-of-the-box support for smoke testing to verify that components render correctly without any errors. Just run pnpm run test-storybook to perform smoke testing. Remember to write stories in JSX or TSX format only. Smoke testing and a lot of other functionalities dont work well with MDX stories.

On this page