Guia de entrevista · Testing

How do you write unit tests with Jest?

do caderno de estudos · atualizado em 2 de outubro de 2026
Para quem vai encarar entrevista de Testing2 min

Faz parte do material de Testing que eu montei a partir das minhas entrevistas. Abaixo, a resposta em inglês e, quando existe, a pegadinha mais comum.

A resposta, como você fala na entrevista

Organize related behavior with describe/it blocks. Each test follows Arrange-Act-Assert: prepare data, perform the action, verify the observable outcome. Use real collaborators when they make the test clear and deterministic. Replace boundaries when a network, clock, or filesystem would make the test unreliable.
Name the behavior, not the private helper sequence. Await or return asynchronous assertions, and test meaningful boundaries and failure cases. A test that only checks a mock was called may miss an incorrect user-visible result.

Ler é o primeiro passo. No app, essa pergunta vira flashcard com repetição espaçada, e o módulo tem quiz e simulado para testar o que ficou.

Treinar essa pergunta no app