angularjs - Test directive attribute without template -


i'm trying run few unit tests on angular directive restricted attribute. i'm trying ascertain directive exists.

does know how test directive attribute only?

here bare bones version of directive

function resetcustomer() {   return {     restrict: 'a',     link: (scope, elem) => {        elem.bind('click', function() {         //do stuff       });     }   }; }  export default {   name: 'resetcustomer',   fn: resetcustomer }; 

... html

<a class="brand" reset-customer>    <img src="path/to/image.jpg"/> </a> 

...and test

describe('unit: resetcustomer', () => {    let element, scope, compile;    beforeeach(() => {     angular.mock.module('app');     angular.mock.inject(($compile, $rootscope) => {       scope = $rootscope.$new();       compile = $compile;       element = angular.element('<a reset-customer></a>');       compile(element)(scope);       scope.$digest();     });   });    it('should exist', () => {     expect(element).tobedefined();   });  }); 

you need first have testable on directive.

for example in callback have assign scope variable isclicked true/false.

then can fire .click in test , have assertion isclicked should true.

you can go mile , have previous assertion isclicked false before fire click. cant rmember method called 90% sure .trigger('click') or mousedown...


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -