Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.6.0 and newer does not let me spy using vitest. #16584

Closed
torgesla opened this issue Dec 1, 2022 · 0 comments · Fixed by #16598
Closed

4.6.0 and newer does not let me spy using vitest. #16584

torgesla opened this issue Dec 1, 2022 · 0 comments · Fixed by #16598
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client.
Milestone

Comments

@torgesla
Copy link

torgesla commented Dec 1, 2022

Bug description

Hi, I'm facing issues in regards to mocking return value when spying on a prisma client. The issue started from Prisma version 4.6.0, and it is still present in 4.7.0. I've attached a minimal reproduction repo for the issue. After 4.6.0, after mocking return value for an initialised prisma client, it still modifies the actual database.

https://github.com/torgesla/prisma-vitest-4.6.0-bug

How to reproduce

  1. Clone https://github.com/torgesla/prisma-vitest-4.6.0-bug
  2. Run "npx vitest", see error
  3. Change prisma and prisma/client versions to "~4.5.0"
  4. Run "npx vitest", see no error

Expected behavior

I expect to be able to spy on and mock return value of prisma client as it worked before v4.6.0 was released.

Prisma information

datasource db {
  provider = "postgresql"
  url      = "postgresql://postgres@localhost:5432/minimal"
}

generator client {
  provider = "prisma-client-js"
}

model Model {
  id   String @id @default(uuid())
  name String
}
import { Model, PrismaClient } from "@prisma/client";
import { it, vi, expect } from "vitest";

const exampleModel: Model = {
  id: "exampleId",
  name: "exampleName",
};
const createData = { name: "FormName" };
const expectedResult: Model = { ...exampleModel, ...createData };

const prisma = new PrismaClient();

vi.spyOn(prisma.model, "create").mockResolvedValue(expectedResult);

it("returns the supplied input data and the generated fields for successfully created Model entry", async () => {
  const result = await prisma.model.create({ data: createData });
  expect(result).toMatchObject(expectedResult);
});

Environment & setup

  • OS: macOS
  • Database: PostgreSQL 14.3
  • Node.js version: 16.14.0

Prisma Version

4.7.0
@torgesla torgesla added the kind/bug A reported bug. label Dec 1, 2022
@eviefp eviefp added kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. labels Dec 2, 2022
@SevInf SevInf added the bug/2-confirmed Bug has been reproduced and confirmed. label Dec 2, 2022
SevInf added a commit that referenced this issue Dec 2, 2022
Some mocking frameworks use `defineProperty` for setting up mocking. In
our proxies, we did not work correctly with it and broke mocking for
them.

Fix #16584
@SevInf SevInf added this to the 4.8.0 milestone Dec 2, 2022
SevInf added a commit that referenced this issue Dec 2, 2022
…#16598)

Some mocking frameworks use `defineProperty` for setting up mocking. In
our proxies, we did not work correctly with it and broke mocking for
them.

Fix #16584
jkomyno pushed a commit that referenced this issue Dec 21, 2022
…#16598)

Some mocking frameworks use `defineProperty` for setting up mocking. In
our proxies, we did not work correctly with it and broke mocking for
them.

Fix #16584
jkomyno pushed a commit that referenced this issue Dec 21, 2022
…#16598)

Some mocking frameworks use `defineProperty` for setting up mocking. In
our proxies, we did not work correctly with it and broke mocking for
them.

Fix #16584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants