angularjs - Angular directive test - Error: [$injector:modulerr] Failed to instantiate module? -
angularjs - Angular directive test - Error: [$injector:modulerr] Failed to instantiate module? -
i using jasmine standalone test angular directories,
simpledirective.js
var app = angular.module("myapp", []); app.controller('simpledirectivecontroller', function($scope) { $scope.customer = { name: 'igor', address: '123 somewhere' }; }); app.directive('helloworld', function() { homecoming { restrict: 'ae', replace: true, // isolate scope: // separate scope within directive scope outside, , map outer scope directive's inner scope. scope: { customerinfo: '=info' }, //templateurl points external html template. templateurl: 'fixture/hello.html' }; });
fixture/hello.html,
<div class="customer"><b>hello</b> {{customerinfo.name}}</div>
simpledirectivespec.js,
describe("simpledirective test ", function(){ // boilerplate starts here... var compile, scope, element; // name of module directive in. beforeeach(module('myapp')); // external template file referenced templateurl. beforeeach(module('fixture/hello.html')); beforeeach(inject(function($compile,$rootscope) { compile = $compile; scope = $rootscope; element = angular.element('<div data-hello-world info="customer"></div>'); compile(element)(scope); scope.$digest(); })); // ...boilerplate ends here it('renders client template', function() { var client = element.find('.customer'); expect(customer.length).tobe(1); }); });
i error,
error: [$injector:modulerr] failed instantiate module fixture/hello.html due to: [$injector:nomod] module 'fixture/hello.html' not available! either misspelled module name or forgot load it. if registering module ensure specify dependencies sec argument.
any ideas have missed?
you should create module template , set template html templatecache.
it should this:
angular.module("fixture/hello.html", []).run(["$templatecache", function($templatecache) { $templatecache.put("fixture/hello.html", "<div class=\"customer\"><b>hello</b> {{customerinfo.name}}</div>"); }]);
if testing karma, there automation karma module purpose called ng-html2js.
angularjs angularjs-directive jasmine
Comments
Post a Comment