angular - 带有自定义类型的角度单元测试给出了找不到命名空间
问题描述
我正在为我的 Angular 项目使用自定义类型,以避免在客户端进行严格类型的返工。但是,它在运行单元测试时不起作用。
我不确定如何在运行单元测试时引入这个命名空间。下面是我们的代码
零件
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
title = 'app';
public employees: Company.Core.DTO.IEmployee[];
}
规格
import { NO_ERRORS_SCHEMA } from "@angular/core";
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('SearchComponent',
() => {
let fixture: ComponentFixture<AppComponent>;
let component: AppComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
schemas: [NO_ERRORS_SCHEMA],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
TypeLite自动生成的文件 (app/typings/Company.typings.ts) 中的输入
declare module Company.Core.DTO {
interface IEmployee {
Number: number;
Age: number;
Name: string;
}
}
执行单元测试时出错
错误 TS2503:找不到命名空间公司
这仅在单元测试编译期间发生。运行应用程序时,我们没有收到此错误。
试过这个Angular2 找不到命名空间 'google'但没有运气
NPM 包
Angular : 8.2.12
jasmine-core : ~3.5.0
karma: ^4.4.1
karma-jasmine : ~2.0.1
typescript: 3.5.3
解决方案
查看您的tsconfig.json
以及如何配置(最有可能)包含Company.typings.ts
. 然后看看你tsconfig.spec.json
的包含Company.typings.ts
相同的方式。我相信你必须玩types
array or typeroots
or includes
。
推荐阅读
- flutter - 如何在 Flutter 中对 TextFormField 进行多次验证?
- python-3.x - 有没有办法访问池中工作进程中的“块”?
- html - 右下角图像上的 div
- c# - arcore 操作脚本中的问题
- kubernetes - 重启集群时出错:等待 apiserver:等待条件超时
- javascript - 当我尝试将它放在 tr td 上时,为什么 jQuery 中继器的添加按钮不起作用?
- arraylist - 如何使用 Leitner System 将数组拆分为子数组并显示项目?
- laravel-5 - 如何从路由中调用文件
- c# - asp.net mvc 5,验证非必填字段(可选字段)
- excel - 创建 en excel 公式并将此公式传递给模块 f2() 的函数出错