I am trying to unit test a component that uses custom pipe. I want to provide a fake implementation of transform
method for my test.
I have found that it is possible to override components, modules, pipe, etc., but I don't see how it is possible to override the behavior (implementation) of component.
I have tried to provide me custom class as a replacement for pipe and it didn't work:
TestBed
.configureTestingModule({declarations: [MyPipe]})
.overridePipe(MDatePipe, {set: MyFakePipe})
I have found similar question on SO How to mock Pipe when testing Component, but suggested solution was to create complete new pipe and provide it to declarations
of testing module which is a bit too much in my opinion.
If overridePipe
won't allow me to override transform
implementation would it be possible to get instance of created MyPipe
class and spyOn
it?
var pipe = TestBed.get(MyPipe);
didn't work either.