19. Unit Testing - biswajitsundara/react GitHub Wiki

Setup

  • Install jest & testing-library
  • npm install --save-dev jest @testing-library/react

Create Tests

  • Create a test directory under src src/tests
  • Under the directory create a test file e.g App.test.js
  • Add the following code
import { render, screen } from "@testing-library/react";
import App from "../../App";

test("Verify the App component is rendered", () => {
  render(<App />);
  const headingElement = screen.getByText('Biz Todo');
  expect(headingElement).toBeInTheDocument();
});

Update vite.config.js

https://dev.to/pacheco/configure-vitest-with-react-testing-library-5cbb

⚠️ **GitHub.com Fallback** ⚠️