Engrain by ByteRush

QLT.06.02 JuniorCore — asked often

Unit and component tests with Vitest and Testing Library

Comes up in: Coding, React

This concept is being written. It gets the full five steps — explanation, predict, interview angle, practice with tests, and review cards. Here is exactly what it will cover, so you can study it elsewhere in the meantime.

What it covers

  • Vitest basics
  • mocking (modules, timers, fetch with MSW)
  • Testing Library queries priority (getByRole first)
  • user-event
  • async utilities (findBy)
  • testing hooks

Words you will know

mockfake timersquery priority

What you will practise

  • test a form component fully

Interview questions this answers

  • Why does Testing Library prefer getByRole?
  • How do you test code that uses timers or fetch?