I'm updating my unit tests for Angular2 RC5. The changelog notes the following breaking change:
addProviders
[is deprecated], useTestBed.configureTestingModule
instead
But this seems to take error only when attempting to include a service in a test. Where my unit test used to do the following:
beforeEach(() => addProviders([
MyService,
MockBackend,
...
]));
it should now configure the test module:
TestBed.configureTestingModule({
providers: [
StoryService,
MockBackend,
...
]
});
But that now throws an error
Service: MyService encountered a declaration exception FAILED
Error: Cannot configure the test module when the test module has already been instantiated. Make sure you are not using
inject
beforeTestBed.configureTestingModule
.
I have checked that inject
isn't been called before the configureTestingModule
. This doesn't affect any other component/directive tests, they seem to pass just fine. How can I resolve this error for unit testing a service with RC5? I realize that I may have to wait until the the testing documentation are updated for RC5 but any insight into possible solutions would be much appreciated.