I am new in Unit testing and i need help in writing TestCase for Sort Pipe in karma. My Custom Sorting Pipe is calling Methods Based on DirectionValue,In which the logic for sorting are.
@Pipe({
name: 'sortBy'
})
export class SortByPipe implements PipeTransform {
transform(value[], direction:string){
if (direction === 'desc'){
this.descendingSort(value);
}
else if(direction === 'asc'){
this.ascendingSort(value);
}
return value;
}
First Case: want to check If it's Calling right Method based on direction value or not.
Second Case: check the result of sort.
I tried to write for something like this for second case.
const direction = 'asc';
const pipe = new SortByPipe();
const result = pipe.transform([4,3,2,1], direction);
expect(result).toBe([1,2,3,4]);
Please Help me understand How i can Solve it. Thanks in Advance