Angular 7测试失败,无法理解原因。有人帮我吗?

时间:2018-12-15 14:38:31

标签: angular angular7

我正在尝试检查联系人列表,但事件不存在。但是我的测试失败了。 (请参阅encoder_last = Lambda(lambda x: x[:,-1,:])(encoder)

这是我的测试代码:component.contacts.length

contacts.component.spec

我的组件:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ContactsComponent } from './contacts.component';
import { ContactClass } from './../shared/models/contact'

describe('ContactsComponent Tests', () => {
  let component: ContactsComponent;
  let fixture: ComponentFixture<ContactsComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ ContactsComponent ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ContactsComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should be no contacts if there is no data', () => {
    expect(component.contacts.length).toBe(0); ---> fails!!
  });

});

错误:

import { Component, OnInit } from '@angular/core';

@Component({
    selector: 'app-contacts',
    templateUrl: './contacts.component.html',
    styleUrls: ['./contacts.component.css']
})
export class ContactsComponent implements OnInit {

    constructor() { }

    ngOnInit() {
    }

}

1 个答案:

答案 0 :(得分:0)

确保组件中的联系人数组为变量