-
Notifications
You must be signed in to change notification settings - Fork 12k
error with DI in unit tests #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Heya, can you show me the failing test? I believe this issue is not due to karma per se, but rather due to the test. |
@filipesilva, Here it is:
Note that eve if I remove the Utils class I still getting issue with the CalendarHelper DI. |
I believe you will also need to add My understanding is that when you are unit testing a service/component/etc, you do not have the injector you have in your tree of components but rather an empty injector to which you can add providers via Thus, when trying to instantiate My understanding may be incorrect, but it is what I used when devising tests for routes. If you generate a route, you will find a test with custom mocks for services in the |
Try this (note Utils added in the array):
|
@filipesilva thanks, it seems to solve the issue with the injections. |
I'm glad it worked! I don't have a definite answer to the 3rd party libs question at the moment, unfortunately. We are working on it, but at the moment the best approach is the one in #274. |
Error: No provider for name! |
@RaghuRangaraj the Angular docs have been updated to include extensive testing documentation: https://angular.io/docs/ts/latest/guide/testing.html This documentation is for Angular 2.0.0 final, so I advise you to update. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I have created some services via
ng g service <NAME>
.I have added the service to
app.ts bootsrap
:Running
ng serve
works correctly and services are injected without any problems.The issue happens when I am running
ng test
:Should I do something in the karma configuration?
Here is the full stacktrace:
The text was updated successfully, but these errors were encountered: