I recently got an enterprise project to write unit tests for. The app is really huge. It has a large injection three. When I'm setting up the tests, it took me half day to mock only the injected services. The problem is, that the service I'm testing, has n
number of injected services, where every injected service has again n
number of injected services and the list goes on an on to an infinite number. Currently I'm mocking them just by creating fake classes, but then again, writing fake methods for every fake class is a huge time consuming task in this project. (mainly because every injected service has a large number of subscriptions in constructors).
My current testing set-up:
class FrameStateServiceStub {
public changedCurrentFrame: Observable<LayerId> = EMPTY;
public changedAvailableFrames: Observable<LayerId> = of("");
public getCurrentFrame(layerId: LayerId): Frame {
return frame;
}
public getAvailableFrames(layerId: LayerId): Frame[] {
return [frame];
}
}
class LoadingIndicatorServiceStub {
}
describe("DisplayService", () => {
const frameStateServiceStub = new FrameStateServiceStub();
const loadingIndicatorServiceStub = new LoadingIndicatorServiceStub();
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
DisplayService,
{provide: FrameStateService, useValue: frameStateServiceStub},
{provide: LoadingIndicatorService, useValue: loadingIndicatorServiceStub},
...
]
});
});
});
I'm wondering if there is an easier (less time consuming) way of doing this?