📚 Cheatsheet

Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.

Snippets 3

Retour
React Testing Library : Rendre un composant
Intermédiaire
import { render, screen } from '@testing-library/react';

it('renders a heading', () => {
  render(<Greeting />);
  const headingElement = screen.getByText(/hello world/i);
  expect(headingElement).toBeInTheDocument();
});
React Testing Library : Requêtes asynchrones
Avancé
it('loads and displays data', async () => {
  render(<MyComponent />)
  const listItem = await screen.findByText(/Item 1/i)
  expect(listItem).toBeInTheDocument()
})
React Testing Library : Simuler un événement
Avancé
import { render, screen, fireEvent } from '@testing-library/react';

fireEvent.click(screen.getByText(/Load/i));