Table of Contents
-
✍️ Volta -
-
✍️ Node Version Manager ✍️ Qwik ✍️ SolidJS Videos ✍️ Axios ✍️ Javascript ✍️ Packages -
✍️ Custom Output ✍️ Editors ✍️ Template Content
✍️ Chocolatey ✍️ Web Resources ✍️ Expose your local Backend ✍️ Git ✍️ Git Commands ✍️ Devlopment Links -
✍️ Build Guides ✍️ Components ✍️ KiCad Examples ✍️ Keyboard Roadmap ✍️ Index ✍️ Keyboards ✍️ Keylayer Plate Thickness ✍️ splitkb ✍️ Tools
| ✍️ | CachyOS |
| ✍️ | Scalable Vector Graphics |
| ✍️ | Roadmap |
Cheatsheet
published: 2026-07-02
Simple and complete cheat sheet Find the PDF version here
render a component
import { render } from '@testing-library/react'
const result = render(<MyComponent />)
search the DOM
- getByRole
import { screen, render } from '@testing-library/react'
render(
<label>
Remember Me <input type="checkbox" />
</label>,
)
const checkboxInput = screen.getByRole('checkbox' , {
name: /remember me/i,
})
interact with element
import { userEvent } from '@testing-library/react'
// userEvent simulates advanced browser interactions like
// clicks, type, uploads, tabbing etc
// Click on a button
userEvent.click(screen.getByRole('button'))
// Types HelloWorld in a text field
userEvent.type(screen.getByRole('textbox'), 'Hello World')
screen
debug(element)|Pretty print the DOM
...queries|Functions to query the DOM
search variants|(result)
getBy|Element or Error
getAllBy|Element[] or Error
queryBy|Element or null
queryAllBy|Element[] or []
findBy|Promise
| search types | (result) |
|---|---|
| Role | <div role='dialog'>...</div> |
| LabelText | <label for="element" /> |
| PlaceholderText | <input placeholder="username" /> |
| Text | <a href='/about'>About</a> |
| DisplayValue | <input value="display value" /> |
| AltText | <img alt="movie poster" /> |
| Title | <span title='Delete' /> or <title /> |
| TestId | <input data-testid='username-input' /> |
text matches
render(<label>Remember Me <input type="checkbox" /></label>)
screen.getByRole('checkbox', {name: /remember me/i}) // ✅
screen.getByRole('checkbox', {name: 'remember me'}) // ❌
screen.getByRole('checkbox', {name: 'Remember Me'}) // ✅
// other queries accept text matches as well
// the text match argument can also be a function
screen.getByText((text, element) => {/* return true/false
*/})
wait for appearance
test('movie title appears', async () => {
render(<Movie />)
// the element isn't available yet, so wait for it:
const movieTitle = await screen.findByText(
/the lion king/i,
)
// the element is there but we want to wait for it
// to be removed
await waitForElementToBeRemoved(() =>
screen.getByLabelText(/loading/i),
)
// we want to wait until an assertion passes
await waitFor(() =>
expect(mockFn).toHaveBeenCalledWith('some arg'),
)
})
| render | options |
|---|---|
| hydrate | if true, will render with ReactDOM.hydrate |
| wrapper | React component which wraps the passed ui |
All credit goes to React Testing Library Github