nestjs
nestjs copied to clipboard
ts-jest: Cannot create mock of a class which has private dependencies in constructor
Error: Argument of type 'typeof PermissionGuard' is not assignable to parameter of type 'PartialFuncReturn<{ prototype: { readonly reflector: ...; readonly rolePermissionService: ...; canActivate: ...; }; }>'. Types of property 'prototype' are incompatible. Type 'PermissionGuard' is not assignable to type 'DeepPartial<{ readonly reflector: Reflector; readonly rolePermissionService: RolePermissionService; canActivate: (context: ExecutionContext) => Promise<...>; }>'. Property 'reflector' is private in type 'PermissionGuard' but not in type 'DeepPartial<{ readonly reflector: Reflector; readonly rolePermissionService: RolePermissionService; canActivate: (context: ExecutionContext) => Promise<...>; }>'
@Injectable()
export class PermissionGuard implements CanActivate {
constructor(
private readonly reflector: Reflector,
private readonly rolePermissionService: RolePermissionService
) {}
}
I am getting the same problem.
did you try writing it like this?
.useValue(createMock<PermssionGuard>())