运行业力单元测试时,出现以下错误:
Chrome 47.0.2526(Linux 0.0.0)错误
未捕获的TypeError:无法读取未定义的属性'_setAsap'
评估路径/node_modules/angular2/bundles/angular2-polyfills.min.js
加载path / node_modules / angular2 / bundles / angular2-时出错polyfills.min.js
该karma.conf.js包含如下:
// Karma configuration
// Generated on Tue Dec 08 2015 14:19:08 GMT-0600 (CST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../',
files: [
'node_modules/angular2/bundles/angular2-polyfills.min.js',
'node_modules/es6-shim/es6-shim.js',
'node_modules/systemjs/dist/system.js',
'node_modules/rxjs//Rx.js',
'node_modules/angular2/bundles/angular2.min.js',
'dist/components/uploader.js',
'dist/components/uploader.spec.js'
],
...
该uploader.js是打字稿编译JavaScript文件,是一个Angular2组件。Uploader.spec.js是单元测试。我使用Karma,SystemJS和Angular2 beta来尝试设置单元测试。
当查看_angular2_polyfills.js_时,_setAsap
似乎指向module es6-promise
。但是,即使我已将其node_modules/es6-promise/dist/es6-promise.js
添加到文件列表中,也无法正常工作。
因此,我遇到了类似的问题,必须将其添加到我的system.conf.js文件中:
System.config({
paths: {
'agular2-polyfills': 'node_modules/angular2/bundles/angular2-polyfills.js',
'typescript': 'node_modules/typescript/lib/typescript.js',
'systemjs': 'node_modules/systemjs/dist/system.js',
'system-polyfills': 'node_modules/systemjs/dist/system-polyfills.js',
'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js'
},
map: {
angular2: 'node_modules/angular2',
rxjs: 'node_modules/rxjs',
crypto: '@empty'// this fixed my last issue
},
meta: {
'path/to/components/*': {
format: 'register'
}
}
});
如果在浏览了几个堆栈问题并阅读了config文档之后,我没有记错(我不声称自己是systemjs ninja),我就来到了这个解决方案,但是我不记得它的某些原因,除了它具有与必须使用业力加载所有内容有关。
我的karma.conf文件数组:
// list of files / patterns to load in the browser
files: [
'node_modules/reflect-metadata/Reflect.js',
'*.spec.js',
'**/*.spec.js',
'**/**/*.spec.js'
]
和karma.conf systemjs配置:
systemjs: {
// Path to your SystemJS configuration file
configFile: 'system.conf.js',
// Patterns for files that you want Karma to make available, but not loaded until a module requests them. eg. Third-party libraries.
serveFiles: [
'client/**/*.js',
'server/**/*.js',
],
// SystemJS configuration specifically for tests, added after your config file.
// Good for adding test libraries and mock modules
config: {
transpiler: null,
defaultJSExtensions: true
},
meta: {
'angular2/angular2':{
format: 'register'
}
}
},
重要说明这可能不是最好的方法,甚至不是最好的方法,但这就是我的工作方式。我尚未在项目的这一部分完成重构阶段,因为在完成项目的第一阶段之后,我将进行重构。
祝你好运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句