References

Basic

<aside> ☝ You should find your elements in the test the same way users will find them! For example, testing-library doesn’t have getById for an input because users don’t care about an id of an element, they find that element by its placeholder text instead.

</aside>

Use data-testid and .getByTestId().

// .tsx
<input
  data-testid="ulid-input"
/>
// .test.tsx
const input = screen.getByTestId('ulid-input')

Watch test only 1 file

yarn test (jest --watch in package.json) then press p to filter based on file name regex.

Expect to be / not to be in document

Find an element

Mocking

Check more in Unit Testing with JestJS