Skip to content
masterclass Buddy

Vitest · Matcher

toThrow

toThrow checks that calling a function throws an error. You can also check the error message or compare the thrown value.

Last updated

Syntax

toThrow(expected?: any): Awaitable<void>

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • expect
  • rejects
  • toEqual
  • toThrowError

Source: expect | Vitest. Checked 2026-11-03.