Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

schoero/repro-vitest-prisma-spies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vitest Prisma Spies Reproduction

This repository contains a minimal reproduction of an issue where Vitest spies do not work with Prisma methods when using Vitest 4 and Prisma 6.

The Issue

In Vitest 4 and Prisma 6, attempting to use vi.spyOn (or vitest.spyOn) on Prisma model methods (e.g., prisma.user.findMany) fails. This is because Prisma 6 uses Proxies for its models and methods, which vi.spyOn in Vitest 4 seems unable to resolve correctly, resulting in an error stating that it "can only spy on a function" but received undefined.

Prerequisites

  • Node.js (v20 or higher recommended)
  • npm

Setup

  1. Install dependencies:

    npm install
  2. Generate Prisma Client:

    npx prisma generate

Running the Reproduction

Run the Vitest test suite:

npm test

Expected Result

The test should pass, and vi.spyOn should successfully attach to the Prisma method.

Actual Result

The test fails with the following error:

Error: vi.spyOn() can only spy on a function. Received undefined.

Working with Vitest v3

Notably, this worked correctly in Vitest v3. You can verify this by downgrading Vitest and running the tests again:

npm i vitest@3
npm t

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors