Ng2 “no locale data” format string triggers in karma test

I have an AngularJS2 base project created using angular-cli. I start with the project just created. In app.component.tsI save the date:

theDate = new Date();

I show it using date:

{{theDate | date}}

The date is correctly displayed and formatted as expected. But if I run ng test, I get the following error:

Failed: Error in ./AppComponent class AppComponent - inline template:4:3 caused by: No locale data has been provided for this object yet.
g@node_modules/karma-intl-shim/lib/shim.js:11:1866
F@node_modules/karma-intl-shim/lib/shim.js:11:8835
k@node_modules/karma-intl-shim/lib/shim.js:11:8335

Test with an error:

it('should render title in a h1 tag', async(() => {
  let fixture = TestBed.createComponent(AppComponent);
  fixture.detectChanges();
  let compiled = fixture.debugElement.nativeElement;
  expect(compiled.querySelector('h1').textContent).toContain('app works!');
}));

package.json:

"karma-intl-shim": "^1.0.3"

karma.conf:

module.exports = function (config) {
  config.set({
    ...
    frameworks: ['jasmine', 'angular-cli', 'intl-shim'],
    plugins: [
      require('karma-intl-shim'),
      ...
    ] ...

Notes:

  • angular-cli "1.0.0-beta.16"
  • I switched to PhantomJSfor convenience, but the same thing happens with Chrome.
  • I performed npm install --saveto install the dependencies.

For ease of reading, the project is saved here .

What is the missing part? Thank.

+4
3

, , , PhantomJS

Package.json

  "dependencies": {  
  "intl": "^1.2.5",
..
   },
 "devDependencies": {
    "karma-intl-shim": "^1.0.3",
    "phantomjs-prebuilt": "~2.1.7",
}

Karma.conf.js

 - frameworks: [... 'intl-shim' ..],
 - plugin: [... require('karma-intl-shim') . ]
 -  files: [{
                pattern: './node_modules/Intl/locale-data/jsonp/en-US.js',
                watched: false
            },]

UPDATE: Intl,

                pattern: './node_modules/Intl/locale-data/jsonp/en-US.js',

VS

                pattern: './node_modules/Intl/locale-data/jsonp/en-US.js',

"I"

+3

angular-cli (1.0.1), polyfills.ts

,

" " import 'intl'; // Run npm install --save intl.

import 'intl/locale-data/jsonp/en';

+1

karma.conf.json files:   './node_modules/Intl/locale-data/jsonp/en-US.js'

0

Source: https://habr.com/ru/post/1661041/


All Articles