簡體   English   中英

如何為角度 4 的自定義排序管道編寫單元測試用例?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM