尝试进行单元测试。出现以下错误:
类型错误:无法读取未定义的属性“原型”
导出类 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 …
我得到了
错误错误:在虚拟文件系统中找不到文件“Roboto-Regular.ttf”
当尝试在 Angular 6 中使用 pdfMake 时。
我做到了
declare module 'pdfmake/build/pdfmake.js';
declare module 'pdfmake/build/vfs_fonts.js';`
Run Code Online (Sandbox Code Playgroud)
在 types.d.ts 中,还有
"typeRoots": [
"node_modules/@types",
"../src/typings.d.ts"
],
Run Code Online (Sandbox Code Playgroud)
在 tsconfig.json 中。
在我使用 pdfmake 的组件中
import 'pdfmake/build/vfs_fonts.js';
import * as pdfMake from 'pdfmake/build/pdfmake.js';
Run Code Online (Sandbox Code Playgroud)
看起来像 vfs_fonts.js 加载,因为我将 console.log 添加到此文件并且它可以工作。
我也尝试添加
<script src="./assets/fonts/vfs.js"></script>
Run Code Online (Sandbox Code Playgroud)
但仍然遇到同样的错误。也许有人为此找到了解决方案?
UPD 1:导入 pdfmake.js 之前没有解决问题
import * as pdfMake from 'pdfmake/build/pdfmake.js';
import 'pdfmake/build/vfs_fonts.js';
Run Code Online (Sandbox Code Playgroud)
解决方案:
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
Run Code Online (Sandbox Code Playgroud)
和
pdfMake.vfs = pdfFonts.pdfMake.vfs;
Run Code Online (Sandbox Code Playgroud)
解决了。
这个例子有什么好的解决办法吗?
好像我有很多模块,就像photo.module.ts我需要DatabaseModule在每个功能模块中导入一样。
尝试将其放入app.module.ts但没有帮助。也许有一些forRoot静态导入的解决方案?