Skip to content

Incomplete solution for handling circular references when testing #636

@KevinKra

Description

@KevinKra

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions