My Angular component depends uses an activatedRoute that has a data parameter set using a resolver service. For my unit tests, I like to mock this out, like this:
activatedRouteStub = {
data: {
subscribe: (fn: (value: Data) => void) => fn({
someObject: SomeObjectMock // hard coded JSON value
}),
}
};
TestBed.configureTestingModule({
declarations: [SomeComponent],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }
]
});
route = fixture.debugElement.injector.get(ActivatedRoute);// where route is in an instance of ActivatedRoute that is injected into SomeComponent as a dependency
This works fine for the initial set of tests that depend on this behavior of activatedRoute. But now, I need to change what is actually returned, basically, I need to use a modified SomeObjectMock and set it to someObject.
And I am short of ideas on how to do it, I have tried doing the following:
route = {
data: {
subscribe: (fn: (value: Data) => void) => fn({
someObject: SomeObjectMock // hard coded JSON value
}),
}
};
This had previously worked when I was stubbing a simple service, changing the definition of a method to return a different value was fairly trivial.
Any suggestions/pointers?