![](/img/trans.png)
[英]How to write unit test cases automatically using SCURI in angular 8 onwards
[英]How to write unit test cases for custom sort pipe in angular 4?
import { Pipe, PipeTransform } from "@angular/core"; import { Opportunity } from "../models/Opportunity"; @Pipe({ name: "orderBy", pure: false }) export class OrderByPipe implements PipeTransform { /** * Method to sort data and return sorted data * * @param records * @param args */ transform(records: Array<any>, args?: any): any { return records.sort(function (a, b) { if (a[args.property] < b[args.property]) { return -1 * args.order; } else if (a[args.property] > b[args.property]) { return 1 * args.order; } else { return 0; } }); } }
在我的项目中,我必须为多列实现排序,所以我想为 angular 4 版本的上述排序自定义管道编写单元测试用例?
我在我的描述中创建了我的管道对象:
const pipe = new OrderByPipe()
然后,执行通常的测试用例,例如: expect(pipe.transform([5,1,6,7]).toEqual([1,5,6,7])
,测试expect(pipe.transform([5,1,6,7]).toEqual([1,5,6,7])
情况等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.