javascript - AngularJS directive link function does not run in Jasmine test -


in jsfiddle have directive.

(function() {      angular.module('myapp', [])         .directive('appfoo', appfoo);      function appfoo() {          console.log('directive factory runs');          return {             controller: appfoocontroller,             link: link,             replace: true,             restrict: 'e',             scope: {                 parentprop: '='             }         };          function appfoocontroller($scope) {              console.log('controller runs');              $scope.render({                 some: 'data'             });          }          function link($scope, $element) {              console.log('link function runs');              $scope.render = function(data) {                 console.log(shared.$scope.parentprop, $element[0], data);             };          }      }  }()); 

and jasmine spec;

describe('myapp::appfoo', function() {      var shared;      beforeeach(function() {          shared = {};         shared.markup = '<app-foo parent-prop="someprop"></app-foo>';          inject(function($compile, $rootscope) {             shared.$compile = $compile;             shared.$parentscope = $rootscope.$new(true);             shared.$rootscope = $rootscope;         });          shared.createdirective = function() {             shared.$element = angular.element(shared.markup);             shared.$compile(shared.$element)(shared.$parentscope);             shared.$parentscope.$digest();             shared.el = shared.$element[0];             shared.$childscope = shared.$element.scope();         };      });      describe('when compiled', function() {          describe('when parameters provided', function() {              beforeeach(function() {                 shared.$parentscope.someprop = {                     a: 'a',                     b: 'b'                 };                 shared.createdirective();             });              it('should have render method', function() {                 expect(typeof shared.$childscope.render).toequal('function');             });          });      });  }); 

the job of link function add render method scope. works in application, in jasmine tests never runs.

i've looked on @ various other questions listed below, no luck.

any appreciated.

[1]

as pointed out @aliasm2k, issue here controller invoked before link function.

because controller calling $scope.render before link function has created it, call stack abandoned , link function not run.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -