Angular 4 @ ngx-translate Karma Jasmin测试用例

时间:2017-09-20 10:45:16

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

尝试整合 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的新手。

2 个答案:

答案 0 :(得分:1)

请在beforeEach块之前更新translateservice的语言

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

答案 1 :(得分:0)

我遇到了类似的问题,并且能够通过删除.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": [],

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