Currently I am overriding providers to use mocked services like this:
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideProviders(AddFieldToObjectDropdownComponent,
[
provide(ServiceA, { useClass: MockServiceA })),
provide(ServiceB, { useClass: MockServiceB }))
])...
I want to do same thing for pipes that the component uses. I tried, provide(PipeA, { useClass: MockPipeA })
and provide(PipeA, { useValue: new MockPipeA() })
but both didn't work.
You can add your mockpipes in the
declarations
of theTestBed
:The
MockPipe
needs to have the@Pipe
decorator with the original name.To stub the pipe, use Dinistro's answer. To spy on the pipe, you can complement that with the following:
Mocking my pipe into simple class like
and simple use of useClass in my spec file
worked for me :-)