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

How did you make the test example work? #2327

Closed
jtlindsey opened this issue Sep 15, 2021 · 4 comments
Closed

How did you make the test example work? #2327

jtlindsey opened this issue Sep 15, 2021 · 4 comments
Labels
docs Documentation creation, updates or corrections

Comments

@jtlindsey
Copy link
Contributor

Hello
How did you make the test example work in here?

import { PrismaClient } from '@prisma/client'
import { mockDeep } from 'jest-mock-extended'
import { DeepMockProxy } from 'jest-mock-extended/lib/Mock'

export type Context = {
  prisma: PrismaClient
}

export type MockContext = {
  prisma: DeepMockProxy<PrismaClient>
}

export const createMockContext = (): MockContext => {
  return {
    prisma: mockDeep<PrismaClient>(),
  }
}

With jest-mock-extended both version 1.0.15 and 2.0.0, DeepMockProxy causes an error Module '"jest-mock-extended/lib/Mock"' has no exported member 'DeepMockProxy'

If I change setup to import { mockDeep, mockReset, DeepMockProxy } from 'jest-mock-extended'; to correlate with marchaos/jest-mock-extended#72 I still get no export member error.

Is this a typescript issue?

Here is my tsconfig.json

{
   "exclude": [
      "node_modules"
   ],
   "compilerOptions": {
      "lib": [
         "es5",
         "es6"
      ],
      "target": "es6",
      "module": "commonjs",
      "moduleResolution": "node",
      "outDir": "./build",
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "sourceMap": true,
      "skipLibCheck": true
   }
}
@jtlindsey jtlindsey added the docs Documentation creation, updates or corrections label Sep 15, 2021
@molebox
Copy link
Contributor

molebox commented Sep 15, 2021

hey @jtlindsey could you try updating jest-mock-extended to version 2.0.1 please and let me know if you can now import DeepMockProxy

@molebox
Copy link
Contributor

molebox commented Sep 15, 2021

We have a community PR #2319 that suggests changing the import path, but i need to clarify their version. Testing on 2.0.2-beta2 the solution in the docs works.

@jtlindsey
Copy link
Contributor Author

hey @molebox I'm on 2.0.2-beta2 and get error Module '"jest-mock-extended"' has no exported member 'DeepMockProxy'

I noticed i can't even do the following:
somefile.ts

export default {
 foo: "foo",
 bar: "bar"
}

anotherfile.ts

import { foo, bar } from './somefile';

I get error that somefile does not have export member foo. Which is making me wonder if my prisma project was created differently. Maybe a different tsconfig.json? I don't know what to look for because i'm new to ts.

@jtlindsey
Copy link
Contributor Author

I still need to investigate my ts issues but import { DeepMockProxy } from 'jest-mock-extended/lib/cjs/Mock'; does work with "jest-mock-extended": "^2.0.2-beta2", thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation creation, updates or corrections
Projects
None yet
Development

No branches or pull requests

2 participants