How to mock Pipe when testing Component

You can add your mockpipes in the declarations of the TestBed: TestBed.configureTestingModule({ declarations: [ AppComponent, MockPipe ], … The MockPipe needs to have the @Pipe decorator with the original name. import {Pipe, PipeTransform} from ‘@angular/core’; @Pipe({name: ‘pipename’}) class MockPipe implements PipeTransform { transform(value: number): number { //Do stuff here, if you want return value; } … Read more

Angular2: custom pipe could not be found

see this is working for me. ActStatus.pipe.ts First this is my pipe import {Pipe,PipeTransform} from “@angular/core”; @Pipe({ name:’actStatusPipe’ }) export class ActStatusPipe implements PipeTransform{ transform(status:any):any{ switch (status) { case 1: return “UN_PUBLISH”; case 2: return “PUBLISH”; default: return status } } } main-pipe.module.ts in pipe module, i need to declare my pipe/s and export it. … Read more

How do I call an Angular 2 pipe with multiple arguments?

In your component’s template you can use multiple arguments by separating them with colons: {{ myData | myPipe: ‘arg1′:’arg2’:’arg3’… }} From your code it will look like this: new MyPipe().transform(myData, arg1, arg2, arg3) And in your transform function inside your pipe you can use the arguments like this: export class MyPipe implements PipeTransform { // … Read more