-
-
Notifications
You must be signed in to change notification settings - Fork 576
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
Problem in Unit Test Environment #39
Comments
I now delete the pending observable in the "onComplete" handler, this should (hopefully) fix your problem, let me know if that's not the case. |
It doesn't solve my problem. I am going to answer the request with the following code backendResponses: string[] = [];
backend = injector.get(XHRBackend);
backend.connections.subscribe((connection: any) => {
connection.mockRespond(
new Response(new ResponseOptions({body: backendResponses[0]}))
);
backendResponses.splice(0, 1);
}); So the request will be answered directly. this.pending will be deleted immediately and undefined will be returned in getTranslation. I cant do it your way to save the connections and and answering them at the end of the test. I need to nest 2 requests. Would there be a problem not to delete pending? I cant remember any problem. |
Maybe not, I need to do more tests |
If I don't set this.pending to undefined, since it is an observable based on http, it will request the translation file whenever a translation is needed :( |
This has been fixed in 1.8.0 ! You shouldn't have a problem with your unit tests anymore :-) |
I written an wrapper arround ng2-translate to perfectly fit my use cases. While testing i dont want to test only my wrapper that it just call your correct functions.
So my function calls translateService.use. The lang isn't available so getTranslation is called. There you load them and subscribe to the pending observable. In this subscription you are going to delete this.pending. This is my problem.
I ve a very similar testing setup like you. The only change is located in the answering of MockBackend conenctions. You are going to save them and answering them when you call your mockBackendResponse function. I will answer them directly when they appear.
So the Observable wil lbe resolvewd directly and the subscription will executed directly before the use function can subscribe to this.pending. This.pending is deleted and i got the following error:
The error seems to be correct thorugh my test environment.
My Question is why are you going to delete this.pending? I removed it and all your tests passes and I could find any problems while running ng2-translate. So is it possible to remove line 134 in translate.service.ts?
Greetings,
Daniel
The text was updated successfully, but these errors were encountered: