Reputation: 311
I've played around with the Angular 2 QuickStart and testing. We really need to separate out the html and css to accommodate for our designers, so using templateUrl etc. is critical. But as soon as I replace template with templateUrl and point to a html file, the tests start failing.
Karma reports "WARN [proxy]: failed to proxy base/app/test.html (socket hang up)", and looking at the network trace, it hasn't translated the URL. All JS is translated to /base/app, but no matter how I mess with files patterns and proxies, it keeps going for /app/test.html instead of /base/app/test.html. In the component, the templateUrl is set to "app/test.html". I've tried all possible variations there too.
The only thing that makes the tests pass is setting include:true for html in karma.conf.js, and pointing to /base/app/test.html in the templateUrl. I had the impression proxying with karma would make "something" in between translate all requested urls?
I've used files from release and latest commits on the quickstart repo.
Edit: This has now been fixed in the angular/quickstart project. :)
https://github.com/angular/quickstart/issues/329#issuecomment-271800205
Upvotes: 2
Views: 1808
Reputation: 208974
I got the same problem when testing the quickstart just right now. I was able to fix it just by changing the appAssets
in the karma.conf.js
from the original base/app/
to /base/app/
From what I understand about the problem is that if you are trying to proxy /app/
, which is what is used in the quickstart's karma.conf
var appAssets = 'base/app/'
proxies: {
"/app/": appAssets
},
why would you replace it with a path that doesn't also have the /
in front. That would cause /app/
to be base/app/
, which it not the same, when you consider how URLs are resolved.
Upvotes: 2