以下是非常简单的Angular组件:
import { Component } from "@angular/core";
@Component({
template: '<h1 style="background: red">Why am I here?</h1>'
})
export class SubmissionFormComponent {
}
这是测试:
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SubmissionFormComponent } from './submission-form.component';
describe('SubmissionFormComponent', () => {
let fixture: ComponentFixture<SubmissionFormComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [SubmissionFormComponent]
}).compileComponents();
fixture = TestBed.createComponent(SubmissionFormComponent);
});
it('true is Truthy', () => {
expect(true).toBeTruthy();
});
});
这是输出: Karma test results with Angular component output
组件模板文字“我为什么来这里?”输出到测试结果页面。
如果我评论测试线:
fixture = TestBed.createComponent(SubmissionFormComponent);
然后“为什么我在这里”消失了。为什么TestBed.createComponent将组件输出到Karma结果页面?