我正在尝试检查联系人列表,但事件不存在。但是我的测试失败了。 (请参阅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() {
}
}
答案 0 :(得分:0)
确保组件中的联系人数组为变量