[英]Angular CLI - Karma test build not finding ng2-material
I'm building out a new Angular 2 app with the Alpha Angular-CLI. 我正在使用Alpha Angular-CLI构建一个新的Angular 2应用程序。 I'm also using the ng2-material library.
我也在使用ng2-material库。 In order to even get it to work I had to do the following:
为了使它工作,我必须做以下事情:
// index.html
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js
},
'ng2-material': {
format: 'cjs',
defaultExtension: 'js',
main: 'all.js'
}
}
});
System.import('app.js').then(null, console.error.bind(console));
// ember-cli-build.js
var materialTree = BroccoliFunnel('node_modules/ng2-material', {
destDir: 'ng2-material'
});
It works fine in the app itself. 它在应用程序本身中运行良好。 However, when I run
ng test
I get the following error: 但是,当我运行
ng test
我收到以下错误:
START:
开始:
13 04 2016 14:55:36.982:WARN [web-server]: 404: /ng2-material/all
13 04 2016 14:55:36.982:WARN [web-server]:404:/ ng2-material / all
Chrome 49.0.2623 (Mac OS X 10.11.3) ERROR
Chrome 49.0.2623(Mac OS X 10.11.3)错误
Error: XHR error (404 Not Found) loading http://localhost:9876/ng2-material/all
错误:XHR错误(404 Not Found)加载http:// localhost:9876 / ng2-material / all
at error (/../node_modules/systemjs/dist/system.src.js:1026:16) at XMLHttpRequest.xhr.onreadystatechange (/../node_modules/systemjs/dist/system.src.js:1047:13)
13 04 2016 14:55:37.058:WARN [web-server]: 404: /ng2-material/all
13 04 2016 14:55:37.058:WARN [web-server]:404:/ ng2-material / all
What am I missing? 我错过了什么?
In your karma-test-shim.js
try loading the module before loading your tests: 在你的
karma-test-shim.js
尝试在加载测试之前加载模块:
System.import('system-config.js').then(function() {
// Load and configure the TestComponentBuilder.
return Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing')
]).then(function (providers) {
var testing = providers[0];
var testingBrowser = providers[1];
testing.TestBed.initTestEnvironment(testingBrowser.BrowserDynamicTestingModule,
testingBrowser.platformBrowserDynamicTesting());
});
///////////////// Add this part /////////////////
}).then(function() {
return System.import('/path/to/ng2-material.js/in/node_modules');
/////////////////////////////////////////////////
}).then(function() {
// Finally, load all spec files.
// This will run the tests directly.
return Promise.all(
allSpecFiles.map(function (moduleName) {
return System.import(moduleName);
}));
}).then(__karma__.start, __karma__.error);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.