加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – ng2日期管道格式化触发karma测试中的“无语言环境数

发布时间:2020-12-17 17:27:27 所属栏目:安全 来源:网络整理
导读:我有一个用angular-cli创建的基本AngularJS2项目.我从新生成的项目开始.在app.component.ts中,我存储了一个日期: theDate = new Date(); 我用日期管道显示它: {{theDate | date}} 日期正确显示并按预期格式化.但如果我运行测试,我会收到以下错误: Failed:
我有一个用angular-cli创建的基本AngularJS2项目.我从新生成的项目开始.在app.component.ts中,我存储了一个日期:

theDate = new Date();

我用日期管道显示它:

{{theDate | date}}

日期正确显示并按预期格式化.但如果我运行测试,我会收到以下错误:

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

失败的测试是:

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'),...
    ] ...

备注:

> angular-cli“1.0.0-beta.16”
>为方便起见,我已切换到PhantomJS,但Chrome也是如此.
>我确实执行了npm install –save来安装依赖项.

为了使读者更容易,项目存储here.

丢失的是什么?谢谢.

解决方法

我实际上是试图寻找解决方案,最后这对我有用,我的所有测试都通过了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
            },]

更新:根据操作系统,Intl的路径可能会有所不同

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

VS

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

注意资本“我”

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读