Replies: 1 comment
-
|
temporary workaround: // src/_testing/utils/suites-fix.ts
import type { Type } from '@nestjs/common';
import type { Mocked } from '@suites/doubles.vitest';
import type { UnitReference } from '@suites/unit';
/** @deprecated temporary fix for PrismaService not correctly typed with NodeNext */
export const unitRefMock = <T>(
ref: UnitReference,
type: Type<T>,
): Mocked<T> => {
return ref.get(type) as unknown as Mocked<T>;
};and then use it in tests like: describe(AccountRepository, () => {
describe('findMany', () => {
it('returns AccountModels as array', async () => {
expect.assertions(2);
const { prismaService, repository } = await mockSolitary();
const { accounts } = prismaAccountMockProxy;
await prismaService.account.findMany.mockResolvedValue(accounts); // <--- TS2349 gone
const result = await repository.findMany();
expect(result).toBe(accounts);
expect(Array.isArray(result)).toBe(true);
});
});
});
const mockSolitary = async () => {
const { unit, unitRef } = await TestBed.solitary(AccountRepository).compile();
return {
prismaService: unitRefMock(unitRef, PrismaService),
repository: unit,
};
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
unsure if this is suites related.
We have to migrate from commonjs to nodenext. We use nestjs 11 with Prisma 6.15. Afaik Prisma changed "something" and now the IDE (PhpStorm) isnt able to resolve the right type anymore. For example this test:
The exact TS2349 error if I hover
mockResolvedValue:If we switch back to commonjs and remove verbatimModuleSyntax from tsoncfig, the error is gone. The type is correct (hovering
mockResolvedValue:The reason is that the type of findMany is not resolved. With commonjs I see (hovering
findMany):and with nodenext I see just nothing.
Resolved types for prismaService and account are the same for commonjs or nodenext.prismaServiceis of TypeMocked<PrismaService>.prismaServiceis of TypeStubbedInstance<PrismaService>.I am working on this the whole day now and I really need some help :)
Edit:
tests are all green btw
Beta Was this translation helpful? Give feedback.
All reactions