Jasmine runner + Angular + directive with external template


Is there a way to test angular directive which use templateUrl? If I do that I get error that my template doesn't exist. Resharper map all files so they are available under /reference/~/ folder. So if in test.js file I reference test2.js and both files are in root folder of my web app, Resharper will serve them under /reference/~/test.js and /reference/~/test2.js. Besides that Resharper only serve files which have been referenced using /// <reference path comments so I cannot change my templateUrl to be /reference/~/template.html since even if template.html exists in the same folder as test.js and test2.js it won't be served by Resharper since it wasn't referenced.

Due to this behaviour there is no way to test angular directive with external template file.

Comment actions Permalink

Hi Guys, really noone test directives with external templates using jasmine and resharper?

Comment actions Permalink

Hello Jakub, I have been struggling with the same problem and have found a (sub optimal) solution through this article: https://attach2process.wordpress.com/category/develop/javascript/ .

Basically, before every test we add the HTML template to the $templateCache using an AJAX request (hello jQuery dependency). If anyone knows of a better way, please share it.

beforeEach(function() {
// Load the module to test

inject(function($templateCache) {

// Verify if the template is already present in the cache
var view = $templateCache.get("/templates/my-awesome-template.html");
if (view) {

// Template not present; retrieve and add it to the cache
type: "GET",
async: false,
cache: false,
url: "../templates/my-awesome-template.html"
.done(function(data) {
$templateCache.put("/templates/my-awesome-template.html", data);
Comment actions Permalink

Thanks Christophe, the issue I have is that resharper start it's own web server to host js files for test. But on this server only referenced files are hosted, so even if i do AJAX request to:


this file doesn't exist when hosted in resharper test web server.


Comment actions Permalink

Is there any update regarding this problem?

Does anyone have any suggestions what to do with the directives with templateUrl defined?


Please sign in to leave a comment.