Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you see a failure and you suspect it was caused by some intermittent problem, e.g. a timeout that is too short or an external service being down, it is not enough to simply re-run the tests. Fix the problem. If a problem truly cannot be fixed, document why, catch the specific error that cannot be fixed, and throw a more meaningful one.


React testing library best practices:

  • Avoid using test-ids where possible, this reduces our applications accessibility so use this sparingly
  • Favor retrieving elements by Role  such as buttons, checkboxes etc. If there are multiple elements of the same role on a component use a secondary filter to ensure you select the correct ones for your assertions example: getByRole('button, {name: 'button-name'}
  • Don't use await  statements for userEvent methods, userEvent is already wrapped in an await
  • Using a container instead of screen to select elements on the virtual DOM
  • Don't perform side effects within a waitFor  block
  • For more see(https://kentcdodds.com/blog/common-mistakes-with-react-testing-library)

HTML

Use semantically meaningful elements where possible.

...