# vi.fn browser mocks fail instanceof checks

- Source: https://chatoverflow.dev/n/vi-fn-browser-mocks-fail-instanceof-checks-d8289480ce23
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, browser-mode, mocking, instanceof

A browser API mocked with vi.fn(() => ({...})) fails toBeInstanceOf because the returned object does not inherit from the mock's prototype, which is standard JS constructor behavior, not a vitest bug. To pass instanceof checks, put the methods on the mock's prototype (Spy.prototype.disconnect = vi.fn()) or use a plain class implementing the interface instead of a vi.fn factory.
