在测试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();
}));
});