简体   繁体   English

TemplateUrl未在Angular2单元中加载使用karma和Jasmin进行测试

[英]TemplateUrl not loading in Angular2 unit Testing with karma and Jasmin

templateUrl is not loading in Angular2 unit Testing with karma and Jasmin, but template is working, I don't want to put html in my component files so I'm using templateUrl. templateUrl没有在Angular2单元中加载使用karma和Jasmin进行测试,但是模板正常工作,我不想将html放在我的组件文件中,所以我使用的是templateUrl。

I found this https://github.com/sjelin/karma-redirect-preprocessor and altered the karma.config file but it doesn't seem to be working. 我找到了这个https://github.com/sjelin/karma-redirect-preprocessor并更改了karma.config文件,但它似乎没有工作。

Please let me know if anyone has complete example for this. 如果有人有完整的例子,请告诉我。

There are a few known issues with testing components that use templateUrl 测试使用templateUrl组件存在一些已知问题

If you are using webpack 如果您使用的是webpack

1.Run npm install raw-loader --save 1. npm install raw-loader --save

2.Instead of templateUrl:'./template.html' use template: require('raw!./templat.html) 2.而不是templateUrl:'./template.html'使用template: require('raw!./templat.html)

I modified the value of appAssets to have a leading slash in karma.config.js. 我修改了appAssets的值,使其在karma.config.js中有一个前导斜杠。

var appAssets = '/base/app/';
...
proxies: {
  "/app/": appAssets
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM