Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import { Pipe } from '@angular/core';
/**
* Create a new pipe with name for tests.
*
* @see https://stackoverflow.com/questions/39293258/how-to-mock-pipe-when-testing-component/41826482#41826482
* ```ts
* translateSpy = jasmine.createSpy().and.callFake((value: any) => value);
* TestBed.configureTestingModule({
* declarations: [
* SomeComponent,
* mockPipe({ name: 'translate' }, translateSpy)
* ],
* // ...
* }).compileComponents();
* ```
*/
export function mockPipe(
options: Pipe,
transformCall: (value: any, ...args: any[]) => any = jasmine.createSpy()
): Pipe {
const metadata: Pipe = {
name: options.name
};
return <any>Pipe(metadata)(
class MockPipe {
transform(value: any, ...args: any[]): any {
return transformCall(value, args);
}
}
);
}
|