-
|
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: // ...
it('returns AccountModels as array', async () => {
expect.assertions(2);
const { prismaService, repository } = await mockSolitary();
const { accounts } = prismaAccountMockProxy;
await prismaService.account.findMany.mockResolvedValue(accounts); // <--- TS2349 here
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: unitRef.get(PrismaService),
repository: unit,
};
};The exact TS2349 error if I hover If we switch back to commonjs and remove verbatimModuleSyntax from tsoncfig, the error is gone. The type is correct (hovering The reason is that the type of findMany is not resolved. With commonjs I see (hovering and with nodenext I see just nothing.
I am working on this the whole day now and I really need some help :) Edit: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
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.
-
|
Hey, thanks for the detailed report and the workaround. This was caused by missing Fixed in npm install @suites/unit@dev @suites/doubles.vitest@dev @suites/di.nestjs@devThe
|
Beta Was this translation helpful? Give feedback.
Hey, thanks for the detailed report and the workaround.
This was caused by missing
.jsextensions in the ESM output of@suites/doubles.vitest(and all other packages). Under NodeNext module resolution, Node.js requires explicit extensions on relative imports. Without them, the ESM entry point fails to load and Suites silently falls back to the CJS build. The CJS build exportsStubbedInstancerather thanMocked, which is whyunitRef.get()was returning the wrong type.Fixed in
3.1.0-dev.0. You can test it now:The
unitRefMockworkaround should no longer be needed. Let us know if you still see the issue after upgr…