4. Testing synchronous vs asynchronous code

This section of The Jest Handbook is dedicated to improving your understanding of Jest’s capabilities around synchronous vs asynchronous code.

You will learn to:

  • test synchronous and asynchronous code that throws
  • setting stubs to mock synchronous and asynchronous outputs
  • failing tests programmatically to check error-handling code

JavaScript’s asynchronous model was not always well supported by test runners.

Jest is Promise-aware and therefore supports async functions as tests (async functions are Promises).

Jump to table of contents