使用karma运行单元测试时,angular-ngx-bootstrap会引发错误

时间:2017-04-25 03:05:50

标签: angular

我目前正在使用与Karma一起运行的ngx-bootstrap遇到问题。 问题是" Chrome 57.0.2987(Windows 10 0.0.0)错误  未捕获的TypeError:无法读取属性'输出'未定义的 在node_modules / ngx-bootstrap / bundles / ngx-bootstrap.umd.js:8087 "

我正在使用角度4.0.0和" ngx-bootstrap":" ^ 1.6.6"。这是我的配置

1。 package.json

"dependencies":
  { 
        "@angular/common": "~4.0.0",
        ........................
        "ngx-bootstrap": "^1.6.6"
  }

2。 Systemjs.config.js

  System.config({
  ......................
    map: {            
        // angular bundles
        ..............................
        'ngx-bootstrap': 'npm:ngx-bootstrap/bundles/ngx-bootstrap.umd.js',                     
    }

});

第3。 karma.conf.js

module.exports = function (config) {
..................   
config.set({
    basePath: '',
    frameworks: ['jasmine'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'), // click "Debug" in browser to see it
      require('karma-htmlfile-reporter') // crashing w/ strange socket error
    ],   
    files: [          
        ...................
       'node_modules/ngx-bootstrap/bundles/ngx-bootstrap.umd.js',         
    ]     

............
    }) }

请帮我弄清问题。 (Web应用程序与ngx-bootstrap运行良好)

谢谢!

1 个答案:

答案 0 :(得分:1)

karma.conf.js中,替换:

node_modules/ngx-bootstrap/bundles/ngx-bootstrap.umd.js

使用:

{
  pattern: 'node_modules/ngx-bootstrap/bundles/ngx-bootstrap.umd.js',
  included: false,
  watched: false
}

然后它有效。