Open aelmanaa opened 7 years ago
Hello,
karma serves files from a different route than your application does.
You have two options to resolve this problem:
I think that the MockBackend solution is the best, because you don't want to do real requests in unit tests. Your point is not to test the loader but to test that your application works well with it. Also the MockBackend gives you plenty of testing options (such as simulating a delay for the request).
Hello ocombe,
thank you very much for your answer. Indeed I m not planning to test the loader but I thought that ng2-translate will be supported by the loader. You ve just suggested a nice workaround , I think it should be documented since I m pretty sure that everyone who uses ng2-translate and tries to unit test a component has encountered the same issue
That's true. I should add a test with that and it could serve as a documentation.
Thanks a lot for this library and for your help as well
+1
Hello, can someone provide an example translate application with unit test (i.e., test the translated values from json).
+1
https://github.com/ngx-translate/core/issues/471 This method work!!!
When I'm trying to fetch a DOM element string, i'm getting whitespace string like ' ' Im using translate pipe for translate
I'm submitting a ... (check one with "x")
Current behavior while running the unit tests with angular-cli ( command ng-test) , my tests fail because the loader of Karma doesn t handle correcterly the /i18n/*.json files. The following exception is returned:
Uncaught SyntaxError: Unexpected token : at src/assets/i18n/en.json
Expected/desired behavior This behavior occurs only when I try to run unit tests. Otherwise my application works perfectly fine. ng2-translate should be compatible with karma/jasmine and we shouldn t get exception while loading *json files
Reproduction of the problem If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:btpW3l0jr5beJVjohy1Q).
run a karma unit test on a component containing the translate filter
What is the expected behavior?
What is the motivation / use case for changing the behavior? I cannot test anymore my components which use ng translate
Please tell us about your environment:
ng2-translate version: 3.1.3
Angular version: 2.1.0
Browser: [Chrome]
Language: [TypeScript 2.0]