Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.
beforeEach(() => {
// Initialisation avant chaque test
});
afterEach(() => {
// Nettoyage après chaque test
});
expect(2 + 2).toBe(4);
const data = { one: 1 };
data['two'] = 2;
expect(data).toEqual({ one: 1, two: 2 });
const mockCallback = jest.fn();
maFonction(mockCallback);
expect(mockCallback).toHaveBeenCalled();
const myMock = jest.fn();
myMock.mockReturnValueOnce(true).mockReturnValueOnce(false);
describe('maFonction', () => {
it('devrait retourner true si le nombre est pair', () => {
expect(maFonction(2)).toBe(true);
});
});
expect(1 + 1).not.toBe(3);
function compileAndroidCode() {
throw new Error('you are using the wrong JDK');
}
it('compiling android goes as expected', () => {
expect(() => compileAndroidCode()).toThrow('you are using the wrong JDK');
});
expect(myVar).toBeTruthy();
expect(myVar).toBeFalsy();
import { render, screen } from '@testing-library/react';
it('renders a heading', () => {
render(<MyComponent />);
const heading = screen.getByRole('heading', { name: /Bonjour/i });
expect(heading).toBeInTheDocument();
});