Angular 管道变径管柱的角度单位试验[]
我尝试使用angular/typeScript为该管道制作测试单元:Angular 管道变径管柱的角度单位试验[],angular,typescript,testing,Angular,Typescript,Testing,我尝试使用angular/typeScript为该管道制作测试单元: @Pipe({ name: 'getCausesFromListCountDailyDelay' }) export class GetCausesFromListCountDailyDelayPipe implements PipeTransform { transform(listCountDailyDelay: ListCountDelay[]): string[] { return listCountD
@Pipe({
name: 'getCausesFromListCountDailyDelay'
})
export class GetCausesFromListCountDailyDelayPipe implements PipeTransform {
transform(listCountDailyDelay: ListCountDelay[]): string[] {
return listCountDailyDelay.map(count => count.cause.charAt(0) + ' ' + count.totalTime);
}
}
当我参加考试的时候,我就有问题了
error TS2339: Property 'toEqual' does not exist on type 'string[]
我的测试文件:
it('should GetCausesFromListCountDailyDelayPipe', () => {
const listCountDailyDelay: ListCountDelay[] = [
{
centre: 'LFAF',
cause: 'CCCC',
totalTime: 5
},
{
centre: 'LFFF',
cause: 'IIII',
totalTime: 20
},
{
centre: 'LFF',
cause: 'FHHH',
totalTime: 10
},
];
const resultDatas: ListCountDelay[] = [
{
centre: 'LFAF',
cause: 'C ',
totalTime: 5
},
{
centre: 'LFFF',
cause: 'I ',
totalTime: 20
},
{
centre: 'LFF',
cause: 'F ',
totalTime: 10
},
];
expect(pipe.transform(listCountDailyDelay).toEqual(resultDatas)));
});
管道转换返回类型字符串[],但我不能用Equal或toBe进行此测试!!!
有什么想法吗 您缺少“expect”的右括号:
expect(pipe.transform(listCountDailyDelay)).toEqual(resultDatas));
你是对的,但是当我通过
toString
更改Equal
时,同样的错误仍然存在,看起来不错,但我不清楚toEqual和use-toString之间的区别,比如:expect(pipe.transform(listCountDailyDelay)).toString(resultdata))代码>