mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-16 04:00:53 -05:00
27 lines
729 B
JavaScript
27 lines
729 B
JavaScript
import React from 'react';
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import { Button } from './button';
|
|
|
|
describe('Button', () => {
|
|
it("should have the role 'button' and the correct text", () => {
|
|
render(<Button label='Hello world' />);
|
|
|
|
expect(
|
|
screen.getByRole('button', { name: /hello world/i })
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it('should trigger the onClick prop on click', () => {
|
|
const onClick = jest.fn();
|
|
render(<Button label='Hello world' onClick={onClick} />);
|
|
|
|
const button = screen.getByRole('button', { name: /hello world/i });
|
|
|
|
userEvent.click(button);
|
|
|
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|