You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should be able to load templateUrls in unit tests #1610
Need something analogous to karma-ng-html2js-preprocessor for Angular1, which allows components using templateUrl to load their template for unit testing.
I implemented this internally by creating a Map<String, String> (templateUrl: HTML) via a build process, and using that with the test bed and a custom TemplateLoader. Angular may consider providing this out of the box.
The API is essentially the same as karma-ng-html2js-preprocessor's (example here, documentation pending), but behind the scenes it works totally differently. Caching the templates client side isn't feasible without an API like $templateCache. Instead, the idea here is to make karma serve the templates at the same URLs that would be used in production. This way they can be retrieved by Angular through AJAX like normal. (Not sure how clear I'm being, it's 3 AM...)
If this makes sense to everyone I'll clean it up and throw it on NPM as soon as I can (I'm busy until Wednesday at 2 PM though). Otherwise I think the only solution is to implement something like $templateCache for Angular2.
I think it should still work in that case. If the templates are inline (as in the design doc example), this plugin is unnecessary. If they're retrieved by AJAX, this plugin will allow the AJAX to work regardless of how the template is formatted.
I'm going to close this issue since I think it solves the problem and there don't seem to be any internal users to ask about it. @zzo, can you update karma-ng-html2js-preprocessor telling them to use karma-redirect-preprocessor in angular2?
@sjelin After trying this out today, I found that it's not the most ideal solution for the angular2 codebase, at least. Similar to angular 1, angular2 uses a mock XHR implementation when running unit tests, so there aren't any real HTTP requests made for karma to handle.
It's seeming more and more that we should have a tool that inlines template contents into the component's JS as some build step (i.e., templateUrl > template in the @View block). Dart already has something like this with the dart transformers.
I think we should precompile templates for unit tests as well. This way,
all templates and also styles will be loaded offline on the server and then
converted into a format that Angular already understands. See #3165
Activity
jbdeboer commentedon May 1, 2015
We need this feature as well, since all of our components use templateUrl and we want to unit test them.
matanlurey commentedon May 15, 2015
I implemented this internally by creating a Map<String, String> (templateUrl: HTML) via a build process, and using that with the test bed and a custom
TemplateLoader. Angular may consider providing this out of the box.matthewjh commentedon May 15, 2015
It would be nice if there was a solution to this that didn't involve a build step, e.g.
Then I could add
templates/**/*.htmlto my karma.conf so that these files are served.34 remaining items
sjelin commentedon Aug 11, 2015
Hey, sorry. My original approach didn't work at all & I haven't been able to make the meeting. Anyway, I have something working here:
https://github.com/sjelin/karma-redirect-preprocessor
The API is essentially the same as karma-ng-html2js-preprocessor's (example here, documentation pending), but behind the scenes it works totally differently. Caching the templates client side isn't feasible without an API like
$templateCache. Instead, the idea here is to make karma serve the templates at the same URLs that would be used in production. This way they can be retrieved by Angular through AJAX like normal. (Not sure how clear I'm being, it's 3 AM...)If this makes sense to everyone I'll clean it up and throw it on NPM as soon as I can (I'm busy until Wednesday at 2 PM though). Otherwise I think the only solution is to implement something like
$templateCachefor Angular2.sjelin commentedon Aug 12, 2015
I didn't get any feedback so I just went ahead an published to NPM: https://www.npmjs.com/package/karma-redirect-preprocessor
Let me know if this solves everyone's problems or I need to go do something else.
jbdeboer commentedon Aug 17, 2015
Per @matanlurey 's July 1 comment, this is no longer an issue for GT. I removed it from the GT hotlist.
tbosch commentedon Aug 18, 2015
Note that we are planning on precompiling templates, see #3605. We probably want to store the templates in this form...
sjelin commentedon Aug 18, 2015
I think it should still work in that case. If the templates are inline (as in the design doc example), this plugin is unnecessary. If they're retrieved by AJAX, this plugin will allow the AJAX to work regardless of how the template is formatted.
I'm going to close this issue since I think it solves the problem and there don't seem to be any internal users to ask about it. @zzo, can you update
karma-ng-html2js-preprocessortelling them to usekarma-redirect-preprocessorin angular2?zzo commentedon Aug 19, 2015
done.
jelbourn commentedon Aug 20, 2015
@sjelin After trying this out today, I found that it's not the most ideal solution for the angular2 codebase, at least. Similar to angular 1, angular2 uses a mock XHR implementation when running unit tests, so there aren't any real HTTP requests made for karma to handle.
It's seeming more and more that we should have a tool that inlines template contents into the component's JS as some build step (i.e.,
templateUrl>templatein the@Viewblock). Dart already has something like this with the dart transformers.ludohenin commentedon Aug 25, 2015
I have one working if you're interested in gulp tool to do that.
https://github.com/ludohenin/gulp-inline-ng2-template
tbosch commentedon Aug 25, 2015
I think we should precompile templates for unit tests as well. This way,
all templates and also styles will be loaded offline on the server and then
converted into a format that Angular already understands. See
#3165
On Tue, Aug 25, 2015 at 9:42 AM Ludovic HENIN notifications@github.com
wrote:
angular-automatic-lock-bot commentedon Sep 7, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.