Angular 2 Unit Test: Custom Pipe error The pipe could not be found Angular 2 Unit Test: Custom Pipe error The pipe could not be found angular angular

Angular 2 Unit Test: Custom Pipe error The pipe could not be found


You should be able to do this:

import { MyPipe } from 'here put your custom pipe path';TestBed.configureTestingModule({    declarations: [ MyComponentUnderTesting, MyPipe ]})


I had the same problem, and fixed it by adding the following "mock pipe" to my spec.ts:

import {Pipe, PipeTransform} from '@angular/core';@Pipe({name: 'myPipe'})class MockPipe implements PipeTransform {    transform(value: number): number {        // blah blah        return value;    }}

Then you have to add MockPipe to the TestBed configureTestingModule declarations:

TestBed.configureTestingModule({  declarations: [ MyComponentUnderTesting, MockPipe ]})


I had almost the same pipe issue; in cases of template parse errors, you need to take two steps:

  1. Import the required pipe at the start like:

    import {{ your_pipe_name }} from '../your/pipe/location';

  2. Add it to your declaration:

    TestBed.configureTestingModule({ declarations: [ your_pipe ] });

Happy Coding!