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

Incomplete solution for handling circular references when testing #636

Open
KevinKra opened this issue Feb 23, 2022 · 0 comments
Open

Incomplete solution for handling circular references when testing #636

KevinKra opened this issue Feb 23, 2022 · 0 comments

Comments

@KevinKra
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant