我有一个用angular-cli创建的基本AngularJS2项目。我从新创建的项目开始。在app.component.ts
,我存储日期:ng2日期管道格式化触发'业余测试中没有本地数据'错误
theDate = new Date();
我使用日期管显示它:
{{theDate | date}}
日期显示正确和如预期格式化。但是,如果我跑ng test
,我得到以下错误:
Failed: Error in ./AppComponent class AppComponent - inline template:4:3 caused by: No locale data has been provided for this object yet.
[email protected]_modules/karma-intl-shim/lib/shim.js:11:1866
[email protected]_modules/karma-intl-shim/lib/shim.js:11:8835
[email protected]_modules/karma-intl-shim/lib/shim.js:11:8335
失败的测试是:
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'),
...
] ...
备注:
- 角(CLI) “1.0.0-beta.16”
- 我切换到
PhantomJS
为了方便但同样具有Chrome
发生。 - 我确实执行了
npm install --save
来安装依赖关系。
为了方便读者阅读,项目存储在here。
缺失的是什么?谢谢。
我karma.conf.json文件中包含的文件:[{ 模式: './src/test.ts',眼睁睁地看着:假} ],它应该是更新文件:[{ 模式:' ./ src/test.ts',看过:false},'./node_modules/Intl/locale-data/jsonp/en-US.js' ] –
@NaveedAhmed,你可能想检查我的答案在这里..http:/ /stackoverflow.com/questions/43182840/no-locale-data-error-in-karma-test-using-phantomjs/43228904#43228904 – N0mi