With Angular version 4.2.4 and angular-cli at version 1.1.3, the code snippet below is used:
import languagesJsonRaw from './languages/en.json';
import countriesJsonRaw from './countries/en.json';
export const languages = prepareLanguages(languagesJsonRaw);
export const countries = prepareCountries(countriesJsonRaw);
Upon running npm start
(which triggers ng serve
), both languages
and countries
are accessible in the application.
However, when executing npm test
, specifically via:
ng test --reporters dots,html --browsers Chrome --watch
The variables languagesJsonRaw
and countriesJsonRaw
turn out to be undefined.
How can I ensure that these files are also available to the test runner? No additional steps were required for them to work with ng serve
or ng build
, even with AOT enabled.
This is a standard angular-cli project, so it's likely using karma as the test runner.
Github Issue: https://github.com/angular/angular-cli/issues/6786