尝试进行单元测试。出现以下错误:
类型错误:无法读取未定义的属性“原型”
导出类 UserService {
构造函数(@InjectRepository(用户)私有只读userRepository:存储库<用户>){}
规格:
describe('AuthController', () => {
let authController: AuthController;
let authService: AuthService;
let mockRepository = {
};
beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [
TypeOrmModule.forFeature([User]),
],
controllers: [AuthController],
providers: [AuthService, {
provide: getRepositoryToken(User),
useValue: mockRepository
}]
}).compile()
authService = module.get<AuthService>(AuthService);
authController = module.get<AuthController>(AuthController)
});
Run Code Online (Sandbox Code Playgroud)
有人可以分享解决方案吗?
更多信息:
所以看起来好像有问题typeorm
beforeEach(async () => {
const module = await Test.createTestingModule({
}).compile()
authService = module.get<AuthService>(AuthService);
authController = module.get<AuthController>(AuthController)
});
Run Code Online (Sandbox Code Playgroud)
使用这段代码我得到了完全相同的错误。所以唯一的问题是添加typeorm到这个测试模块。
所以它因为依赖而失败:AuthController->AuthService->UserService->TypeORM …