Created
August 26, 2013 15:37
-
-
Save vtanathip/6342831 to your computer and use it in GitHub Desktop.
In Angular when you want to unit test directive with templateUrl you must compile html to js and put it in $templateCache for use it ( solution is very easy with this plugin https://github.com/ericclemmons/grunt-angular-templates )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngtemplates: { | |
myApp: { | |
options: { | |
base: 'app/templates', // $templateCache ID will be relative to this folder | |
prepend: 'templates/', // path to your templates files ( this will add path to it ) | |
module: { | |
name: 'myAppTemplate', // (Optional) Explicitly define module name | |
define: true // (Optional) Define new module (Default: false) | |
} | |
}, | |
src: 'app/templates/**.html', | |
dest: 'app/compiled/templates.js' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Testing compile angular directive with templateUrl', function() { | |
var scope, | |
elem, | |
compiled, | |
html; | |
//load the module | |
beforeEach(module('myApp')); | |
// load the templates | |
beforeEach(module('myAppTemplate')); | |
beforeEach(function (){ | |
//set our view html. | |
html = '<numpad></numpad>'; | |
inject(function($compile, $rootScope) { | |
//create a scope (you could just use $rootScope, I suppose) | |
scope = $rootScope.$new(); | |
//get the jqLite or jQuery element | |
elem = angular.element(html); | |
//compile the element into a function to | |
// process the view. | |
compiled = $compile(elem); | |
//run the compiled view. | |
compiled(scope); | |
//call digest on the scope! | |
scope.$digest(); | |
}); | |
}); | |
it(' should be compiled and now you can focus another behavior',function(){ | |
//do something beautiful here. . . | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment