React Testing Library: Simple and Complete Cheat Sheet
React Testing Library: Simple and Complete Cheat Sheet
github.com/test-library/react-testing-library
search the DOM queryAllBy Element[] or [] // the element is there but we want to wait for it
// to be removed
await waitForElementToBeRemoved(() =>
import { screen, render } from '@testing-library/react' findBy Promise<Element> or Promise<rejection> screen.getByLabelText(/loading/i),
)
render( findAllBy Promise<Element[]> or
<label> Promise<rejection> // we want to wait until an assertion passes
Remember Me <input type="checkbox" /> await waitFor(() =>
</label>, expect(mockFn).toHaveBeenCalledWith('some arg'),
) )
})
const checkboxInput = screen.getByRole('checkbox', {
name: /remember me/i,
}) search types (result)
import userEvent from '@testing-library/user-event' PlaceholderText <input placeholder=“username” /> wrapper React component which wraps the passed ui
screen
Visit our playground at: https://testing-playground.com and did you try out the eslint plugins?