Skip to content
masterclass Buddy

Vitest · Matcher

toHaveBeenCalled

expect(spy).toHaveBeenCalled() checks that a mock or spy function ran at least once. Add .not to assert that it was not called.

Last updated

Syntax

expect(actual).toHaveBeenCalled()

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

Subscribe
  • toHaveBeenCalledTimes
  • toHaveBeenCalledWith
  • toHaveBeenCalledExactlyOnceWith
  • toHaveBeenLastCalledWith
  • toHaveBeenNthCalledWith
  • vi.fn
  • vi.spyOn

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