@Component({
selector: ‘test-information’,
templateUrl: ‘./test-information.component.html',
styleUrls: [‘./test-information.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class TestInformationComponent implements OnInit, OnChanges {
@Input() info: Array<any>;
constructor()
{
}
ngOnInit()
{
}
ngOnChanges(changes: SimpleChanges) {
console.log(“value”,changes.info.currentValue);
}
}
因此,基本上,这个组件应该接收对象数组作为输入。
该组件的测试用例如下
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, ViewChild } from '@angular/core';
import { TestInformationComponent } from './test-information.component';
import { MaterialModule } from '../../modules/material/material.module';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { of } from 'rxjs';
import { By } from '@angular/platform-browser';
fdescribe('TestInformationComponent', () => {
let component: TestInformationComponent;
let fixture: ComponentFixture<TestInformationComponent>;
let fixture1,hostComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TestInformationComponent],
imports: [MaterialModule],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
}));
beforeEach(async(() => {
fixture = TestBed.createComponent(TestInformationComponent);
component = fixture.componentInstance;
fixture.detectChanges();
component.info = [
{
"id": "19",
"name": "test”,
"Score": 36,
"status": “up”
}
];
fixture.detectChanges();
}));
it('should create', () => {
console.log("componetis ",component);
expect(component).toBeTruthy();
});
});
这个简单的单元测试用例失败了,我得到以下错误: 失败:无法读取未定义的属性“ test”
我不知道我要去哪里错了。