Uncaught TypeError:无法读取未定义引发的属性“ subject”-Karma v4.1.0

时间:2019-09-17 07:08:14

标签: angular unit-testing jasmine karma-runner testcase

我创建了一个新的PreviewComponent,它为空。 在单元测试中显示错误无法读取未定义的抛出属性'subject' 但是我没有在组件中声明任何变量。

enter image description here

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

0 个答案:

没有答案