Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a custom pipe called 'myPipe'. I am getting:

The pipe 'myPipe' could not be found error

in my unit test ts. Pleas advice what to import and declare in my .spec.ts

Here is my .spec.ts

import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core';  import { MyComponent } from './main-page-carousel.component';  describe('CarouselComponent', () => {   let component: MyComponent ;   let fixture: ComponentFixture<MyComponent>;    beforeEach(async(() => {     TestBed.configureTestingModule({       declarations: [ MyComponent ],     })     .compileComponents();   }));    beforeEach(() => {     fixture = TestBed.createComponent(MyComponent);     component = fixture.componentInstance;     fixture.detectChanges();   });    it('should create', () => {     expect(component).toBeTruthy();   }); }); 

Thanks!

like image 808
Si Thu Avatar asked Jan 09 '17 07:01

Si Thu


People also ask

Which of the following is NOT example of pipe in angular?

Answer: B) DataPipe Is not built-in a pipe in angular.

What is pipe in angular example?

Pipes were earlier called filters in Angular1 and called pipes in Angular 2 and 4. It takes integers, strings, arrays, and date as input separated with | to be converted in the format as required and display the same in the browser.


1 Answers

You should be able to do this:

import { MyPipe } from 'here put your custom pipe path';  TestBed.configureTestingModule({     declarations: [ MyComponentUnderTesting, MyPipe ] }) 
like image 125
JonesCola Avatar answered Sep 22 '22 01:09

JonesCola