我创建了一个新的PreviewComponent,它为空。 在单元测试中显示错误无法读取未定义的抛出属性'subject' 但是我没有在组件中声明任何变量。
preview.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-preview',
templateUrl: './preview.component.html',
styleUrls: ['./preview.component.css']
})
export class PreviewComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
preview.component.spec.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PreviewComponent } from './preview.component';
describe('PreviewComponent', () => {
let component: PreviewComponent;
let fixture: ComponentFixture<PreviewComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [PreviewComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PreviewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});