question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unit test Karma/jasmine: error while loading json language files

See original GitHub issue

I’m submitting a … (check one with “x”)

[x ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

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]

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
mmarimuthucommented, May 10, 2017

Hello, can someone provide an example translate application with unit test (i.e., test the translated values from json).

2reactions
ocombecommented, Nov 17, 2016

That’s true. I should add a test with that and it could serve as a documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to load external Json file using karma+Jasmine for ...
The workaround is to add a fake URL parameter like require('./data.json?test=') . This will turn into data.json?test=.js which will still locate the file....
Read more >
Find out how much code you're testing - Angular
The CLI can run unit tests and create code coverage reports. Code coverage reports show you any parts of your code base that...
Read more >
Sample Project On Front-End Unit Testing Using KARMA And ...
This error comes up as we are loading an empty file. Hence, just simply create the JSON file to hold an empty object...
Read more >
Testing Extensions - Visual Studio Code
We refer to these tests as integration tests, because they go beyond unit tests that can run without a VS Code instance. This...
Read more >
Testing Angular 2 Services and Http with Jasmine
If you're getting the same error, you need to make sure you're telling the mock client that the content type is application/json. I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found