angularjs - Unit-testing a directive with isolated scope, bidirectional value and ngIf -


i want unit test directive looks this:

angular.module('myapp', []) .directive('mytest', function () {     return {         restrict: 'e',         scope: { message: '='},         replace: true,         template:  '<div ng-if="message"><p>{{message}}</p></div>',         link: function (scope, element, attrs) {         }     }; }); 

here failing test:

describe('mytest directive:', function () {      var scope, compile, validhtml;      validhtml = '<my-test message="message"></my-test>';      beforeeach(module('myapp'));      beforeeach(inject(function($compile, $rootscope){         scope = $rootscope.$new();         compile = $compile;     }));      function create() {         var elem, compiledelem;         elem = angular.element(validhtml);         compiledelem = compile(elem)(scope);         scope.$digest();          return compiledelem;         }      it('should have scope on root element', function () {           scope.message = 'not empty';         var el = create();         console.log(el.text());         expect(el.text()).tobedefined();         expect(el.text()).not.tobe('');     });  }); 

can spot why it's failing?

the corresponding jsfiddle

thanks :)

 console.log((new xmlserializer()).serializetostring(el.get(0))); 

returns

 <!-- ngif: message -->  

because using replace without parent element in validhtml combinaison of ng-if .so either change validhtml , add div parent.

or

test expectations on next sibling of el

el.next()  

which be

<div ng-if="message" message="message" class="ng-scope"><p class="ng-binding">yes</p></div>  

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -