TypeError未捕获[对象对象] thrownr未捕获[对象对象] thrown

时间:2019-03-08 16:38:20

标签: unit-testing angular6 karma-jasmine

在测试ng test --code-coverage true时出现此错误:

  

错误:未捕获的[对象对象]被抛出

Spec.ts文件:

 import { async, ComponentFixture, TestBed, inject, tick, fakeAsync } from 
 '@angular/core/testing';
 import { NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA, Injectable, 
 DebugElement, 
 Inject } from '@angular/core';
 import {CustomComponent} from './custom-component';
 describe('CustomComponent', () => {
 let component: CustomComponent;
 let fixture: ComponentFixture<CustomComponent>;
 beforeEach(async(() => {
 TestBed.configureTestingModule({
 imports: [ReactiveFormsModule, FormsModule, CookieModule.forRoot(), 
 HttpClientModule, HttpModule],
 declarations: [CustomComponent],
 providers: [],
 schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA]
 }).compileComponents();
 }));
 beforeEach(fakeAsync(() => {
fixture = TestBed.createComponent(CustomComponent);
component = fixture.componentInstance;
fixture.detectChanges();
tick();
}));
it('is form invalid when empty', fakeAsync(() => {
const fixture = TestBed.createComponent(CustomComponent);
const component = fixture.debugElement.componentInstance;
fixture.detectChanges();
expect(component.form.valid).toBeFalsy();
}));
});

0 个答案:

没有答案