graphql-prisma-typescript icon indicating copy to clipboard operation
graphql-prisma-typescript copied to clipboard

Incomplete solution for handling circular references when testing

Open KevinKra opened this issue 3 years ago • 0 comments

Here is the repo I created (based off of the Prisma docs) I've been having difficulty trying to get tests passing per the resources provided in the docs. There is a reference to resolve the circular reference issue appearing for the context (and maybe also singleton) solutions. However, there is no instruction within the docs that shows how to configure the .jest.config.js to leverage the .tsconfig file.

The following solution resolves that:

// jest.config.js
module.exports = {
  clearMocks: true,
  preset: "ts-jest",
  testEnvironment: "node",
  setupFilesAfterEnv: ["<rootDir>/singleton.ts"],
  globals: {
    "ts-jest": {
      tsconfig: "./.tsconfig",
      // set global config for ts-jest
    },
  },
};

with that update to jest.config.js in place, the following error goes away and the tests pass:

Screen Shot 2022-02-22 at 10 25 14 PM

However, the error still persists within the file itself.

Screen Shot 2022-02-22 at 10 26 36 PM

the following provides a bandaid solution in the event that a linter is pipeline is getting jammed up.

  // @ts-ignore
  prismaMock.user.create.mockResolvedValue(user);

It's also worth noting, the solution used above evidently works without having "strictNullChecks": true within .tsconfig

KevinKra avatar Feb 23 '22 05:02 KevinKra