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

TypeError: Cannot read properties of undefined (reading 'dmmf') #1103

Open
Fasuh opened this issue Sep 24, 2024 · 2 comments
Open

TypeError: Cannot read properties of undefined (reading 'dmmf') #1103

Fasuh opened this issue Sep 24, 2024 · 2 comments

Comments

@Fasuh
Copy link

Fasuh commented Sep 24, 2024

Hello, i have an issue trying to implement this package. It seems like im missing some configuration, and i cannot seem to be able to make it work.

I am getting an error
TypeError: Cannot read properties of undefined (reading 'dmmf')

I have seen some threads talking about this issue but unfortunately all of them had been closed without much explaination of how this was fixed.

I am using Typescript

I have created a folder called __mocks__ with a subfolder @prisma and a file client.ts
with content of

import { PrismockClient } from 'prismock';

export * from '@prisma/client';
export { PrismockClient as PrismaClient };

my test looks like this

let repository: RepositoryImpl;
let database: SinonStubbedInstance<AppDatabase>;

beforeEach(() => {
  cleanUpMetadata();
  database = createStubInstance(PgDatabase);
  repository = new RepositoryImpl(database);
});

afterEach(() => {
  jest.restoreAllMocks();
});

describe("#getList", () => {

  it("#getList returns a list", async () => {
    // arrange
    const prismock = new PrismockClient()
    database.connect.resolves(prismock as PrismaClient);

    // act
    const result = await repository.getList(true);

    // assert
    expect(result).toEqual([]);
  });
});

My prisma versions are
"prisma": "^5.19.0"
"@prisma/client": "^5.18.0"
"prismock": "^1.33.3"

And my node version is 20.0.0

and after trying to run it, i am getting the error mentioned above. I would greatly appreciate help as i believe some kind of prisma mocking is essential for my project.

@morintd
Copy link
Owner

morintd commented Sep 28, 2024

Hello @Fasuh , I haven’t been able to reproduce with your exact use case, but I believe you should’nt mock Prisma through the mocks, if you are instantiating Prismock yourself.

If you can’t get it to work, is there any chance you can provide a public reproduction repo?

@jamesread
Copy link

Hey @morintd , thanks for Prismock, I'm very keen to try and start using it on a project I'm contributing to called postiz.

I'm literally writing the very first unit tests for this project, and I'll admit that I'm really not that familiar with the javascript ecosystem, jest, etc, so I may not be doing something correct here, however I have a reproducer on a public branch; gitroomhq/postiz-app#331

You'll see in that PR that I'm using the mocks directory approach.

I've checked the .prisma file, and it's not using a custom client path; https://github.com/gitroomhq/postiz-app/blob/f6d386b2130d94d4e4f759a6802ae49fcdc5c310/libraries/nestjs-libraries/src/database/prisma/schema.prisma#L4

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

3 participants