简体   繁体   中英

Angular karma-jasmine failing for pipe DatePipe

I am using Angular2 and having parent child components. My child component is using DatePipe provider due to which parent unit test is failing and giving below error,

Error: Illegal state: Could not load the summary for pipe DatePipe.

How to resolve this?

Update: Resolved the issue. I was adding DatePipe as provider in my child component that's no more needed. Don't need to inject pipes. Use the underlying function of the pipe directly instead. All the Angular ones are public now.

//Just import DatePipe
import {DatePipe} from '@angular/common';

//In class definition create the instance of the DatePipe
datePipe = new DatePipe('en-US');

// And just call the transform method
console.log(this.datePipe.transform(dateValue, 'MM/dd/yyyy'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM