为了账号安全,请及时绑定邮箱和手机立即绑定

类型错误:无法读取未定义的属性“id” - Angular 8 测试

类型错误:无法读取未定义的属性“id” - Angular 8 测试

九州编程 2021-08-26 16:50:26
尝试在我的 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();  })    });
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 223 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信