尝试在我的 angular 8 应用程序中执行单元测试时,我收到 TypeError: cannot read property 'id' of undefined 。这是我的模板<h4>{{student.id}}</h4>这是我的组件import {Component, EventEmitter, Input, OnInit} from '@angular/core';import { Student } from '@app/app-types';@Component({...... saved some typing})export class StudentComponent implements OnInit {@Input() student: Student;refreshForm: EventEmitter<any>;constructor(){}ngOnInit(){ this.refreshForm = new EventEmitter(); }}这是单元测试import {async, ComponentFixture, TestBed } from '@angular/core/testing';import {StudentComponet} from './student-component';describe('StudentComponet', () => { let component: StudentComponent; let fixture: ComponentFixture<StudentComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [StudentComponent] }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(StudentComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }) });
添加回答
举报
0/150
提交
取消