【问题标题】:Angular 4 @ngx-translate Karma Jasmin test casesAngular 4 @ngx-translate Karma Jasmine 测试用例
【发布时间】:2018-03-01 09:25:57
【问题描述】:

尝试集成 Angular 4 + @ngx-translate。一切都在使用npm start 正常执行和工作。当我尝试npm test 运行 Karma 测试用例时出现问题。所有这些都是在添加 @ngx-translate 功能之后开始的。 控制台出现以下错误:

20 09 2017 14:24:30.334:INFO [Chrome 60.0.3112 (Windows 7 0.0.0)]: Connected on socket n1uvSjMzMfCGU26zAAAA with id 7587189
Chrome 60.0.3112 (Windows 7 0.0.0) ERROR
  Uncaught TypeError: Cannot read property 'Injectable' of undefined
  at node_modules/@ngx-translate/core/bundles/core.umd.js:817

在浏览器控制台上:

Uncaught TypeError: Cannot read property 'Injectable' of undefined
    at Object.<anonymous> (core.umd.js:817)
    at __webpack_require__ (core.umd.js:30)
    at Object.module.exports (core.umd.js:1421)
    at __webpack_require__ (core.umd.js:30)
    at module.exports (core.umd.js:76)
    at core.umd.js:79
    at webpackUniversalModuleDefinition (core.umd.js:9)
    at core.umd.js:10
ng-bootstrap.js:9 Uncaught TypeError: Cannot read property 'core' of undefined
    at webpackUniversalModuleDefinition (ng-bootstrap.js:9)
    at ng-bootstrap.js:10

在浏览器上:

OtherComponent when inside a test host should process Instance name
TypeError: Cannot read property 'bpmWrapWorkItemList' of undefined
TypeError: Cannot read property 'bpmWrapWorkItemList' of undefined

请帮忙!!!我是 Angular 4 的新手..

【问题讨论】:

    标签: karma-jasmine bootstrap-4 translate ngx-translate


    【解决方案1】:

    我遇到了类似的问题,并且能够通过删除 .angular-cli.json 中的两个脚本定义来解决问题。

    我换了

    "scripts": [
        "../node_modules/@ngx-translate/core/bundles/core.umd.js",
        "../node_modules/@ngx-translate/http-loader/bundles/http-loader.umd.js"
    ],
    

    "scripts": [],
    

    虽然这解决了问题,并且翻译服务仍然有效,但我不知道为什么首先需要这些脚本,以及是否可以删除它们。

    【讨论】:

      【解决方案2】:

      请在每个块之前为翻译服务更新语言

      beforeEach(inject([TranslateService], (service: TranslateService) => {
          service.use('de');
        }));
      

      【讨论】:

        猜你喜欢
        • 2021-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-07
        • 1970-01-01
        • 2018-01-31
        • 2015-12-10
        • 1970-01-01
        相关资源
        最近更新 更多