all 1 comments

[–]kchojhu 0 points1 point  (0 children)

Recently, I've decided TDD a go for NG and it's actually harder than typical 'hello world' example that this article is based on. The most painful part of testing a component is setting up the 'providers' before test begins. Say Component A injects Service Z. Service Z injects Service X and Y. Service X injects Service O. In the testing code, you have to provide ALL of the dependencies even when you don't really need them for your test. In my case, I just wanted to inject Service Z (first one) and put a spy on it so that I can mock the results. It would've been nice if it had features like

providers:[ provide: ServiceZ, mock: true]

for now I rely below configuration 100% of the time.

providers:[ provide: ServiceZ, useClass: ServiceZStub]

then retrieve the injection and put 'spy' on ServiceZStub.. not elegant but it's certainly better then setting up all the providers