我正在学习本教程:https://angular.io/guide/testing#component-test-scenarios for karma + jasmine unit testing.这是我的代码:
import { AppComponent } from "./app.component";
import { ComponentFixture, TestBed } from "@angular/core/testing";
describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
let h1: HTMLElement;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ AppComponent ],
});
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
h1 = fixture.nativeElement.querySelector('h1');
});
it('should display original title', () => {
expect(h1.textContent).toContain("Ciao");
});
});
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,我得到以下异常:
TypeError: Cannot read property 'getComponentFromError' of null
at TestBed._initIfNeeded (D:/Users/apwzp/AppData/Local/Temp/karma-typescript-bundle-11944DDd01l2f5Y0P.js:1020:52)
at TestBed.createComponent (D:/Users/apwzp/AppData/Local/Temp/karma-typescript-bundle-11944DDd01l2f5Y0P.js:1174:14)
at …Run Code Online (Sandbox Code Playgroud)