Last active
May 13, 2024 04:37
-
-
Save Offirmo/1d7b9344935369c5ca33959500cf6e26 to your computer and use it in GitHub Desktop.
[react testing library] #react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://testing-library.com/docs/react-testing-library/migrate-from-enzyme | |
// getByRole, queryByRole, getAllByRole, queryAllByRole, findByRole, findAllByRole | |
// getByLabelText, queryByLabelText, getAllByLabelText, queryAllByLabelText, findByLabelText, findAllByLabelText | |
// getByPlaceholderText, queryByPlaceholderText, getAllByPlaceholderText, queryAllByPlaceholderText, findByPlaceholderText, findAllByPlaceholderText | |
// getByText, queryByText, getAllByText, queryAllByText, findByText, findAllByText | |
// getByDisplayValue, queryByDisplayValue, getAllByDisplayValue, queryAllByDisplayValue, findByDisplayValue, findAllByDisplayValue | |
// getByAltText, queryByAltText, getAllByAltText, queryAllByAltText, findByAltText, findAllByAltText | |
// getByTitle, queryByTitle, getAllByTitle, queryAllByTitle, findByTitle, findAllByTitle | |
// getByTestId, queryByTestId, getAllByTestId, queryAllByTestId, findByTestId, findAllByTestId | |
screen.getByText('456').closest('a') | |
screen.getByRole('button', { name: EXPECTED_LABEL }) | |
////////////////////////// | |
// https://testing-library.com/docs/dom-testing-library/api-debugging | |
screen.getByRole('foobar') | |
screen.debug() | |
////////////////////////// | |
// REACT https://testing-library.com/docs/react-testing-library/api | |
const { rerender } = renderWithDi(<ComponentForTest />); | |
rerender(<ComponentForTest />); | |
jest.useFakeTimers(); | |
const { rerender } = renderWithDi(<ComponentForTest />, DEPS); | |
act(() => { | |
jest.runAllTimers(); | |
}); | |
rerender(<ComponentForTest />); | |
////////////////////////// | |
// https://github.com/testing-library/jest-dom | |
toBeDisabled | |
toBeEnabled | |
toBeEmptyDOMElement | |
toBeInTheDocument | |
toBeInvalid | |
toBeRequired | |
toBeValid | |
toBeVisible | |
toContainElement | |
toContainHTML | |
toHaveAccessibleDescription | |
toHaveAccessibleErrorMessage | |
toHaveAccessibleName | |
toHaveAttribute | |
toHaveClass | |
toHaveFocus | |
toHaveFormValues | |
toHaveStyle | |
toHaveTextContent | |
toHaveValue | |
toHaveDisplayValue | |
toBeChecked | |
toBePartiallyChecked | |
toHaveRole | |
toHaveErrorMessage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment