jasmine - 如何修复 [karma-server]:未捕获的异常
问题描述
我正在运行 Angular 9 应用程序,并且正在使用以下命令在 jasmine 中运行单元测试来运行测试,一切正常:
ng test
但是,当我使用 watch=false 运行单元测试时,所有测试都通过了,但最后我得到了“ UncaughtException ”。
ng test --watch=false // using this command in SonarQube to generate UT report
由于上述错误,SonarQube 未生成 UT 报告。
有什么方法可以获取错误的详细信息(日志文件或其他内容)或调试 [karma-server]" UncaughtException 错误...?
我从以下规范文件中收到错误:
profile.component.spec.ts
describe('Client.App.Advanced.ProfileComponent', () => {
let component: ProfileComponent;
let fixture: ComponentFixture<ProfileComponent>;
let httpMock: HttpTestingController;
function mockHttp(data) {
const mockReq = httpMock.expectOne((req) => true);
mockReq.flush(data);
httpMock.verify();
}
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, RouterTestingModule],
declarations: [ProfileComponent],
providers: [ProfileToolHandlerService ]
}).compileComponents();
}));
beforeEach(fakeAsync(() => {
httpMock = TestBed.inject<HttpTestingController>(HttpTestingController);
fixture = TestBed.createComponent(ProfileComponent);
component = fixture.componentInstance;
fixture.detectChanges();
// mock request for Login
mockHttp(null);
tick();
}));
it('shall create the component', () => {
fixture.detectChanges();
expect(component).toBeDefined();
});
}
解决方案
推荐阅读
- vba - 在VBA中的单词选项卡中锁定单元格内容
- javascript - toThrow 检查数组的不可更改性
- c# - 当 asp.net 中同一域中的一封电子邮件错误时,电子邮件失败
- python - 生成器不会遍历所有文件
- ios - iOS:我可以从图库中获取视频的 AVMetadataFaceObject 吗?
- python - Python:使用代理服务器访问谷歌云存储
- python-3.x - 比较具有不同形状的熊猫数据框
- python - 如何在 Python 中使用 copy_reg.pickle 注册类型“SwigPyObject”?
- javascript - TypeError:使用 Passport.js 时无法读取未定义的属性“headersSent”
- node.js - MIME 多部分流的意外结束。MIME 多部分消息不完整。使用 axios