i want simple jasmine test test following directive:
'use strict'; angular.module('kits.ui.components') .directive('toggle', function() { return { restrict: 'e', require: 'ngmodel', scope: { ontext: '@', offtext: '@', ngmodel: '=', label: '@' }, templateurl: 'modules/ui.components/toggle/views/toggle.view.html' }; }); what best approach , recommendation such simple directives?
toggle view:
<div> <label data-auto="togglelabel" for="toggle-input-{{$id}}" class="col-sm-2 control-label"> {{label}} </label> <div class="col-sm-10 checkbox-inline"> <label class="cnc-toggle"> <input data-auto="toggleinput" ng-model="ngmodel" id="toggle-input-{{$id}}" type="checkbox" class="toggleinput"> <div class="track"> <div ng-show="ngmodel" class="toggle-label on"> {{ontext || 'on'}} </div> <div ng-show="!ngmodel" class="toggle-label off"> {{offtext || 'off'}} </div> <div class="handle"></div> </div> </label> </div> </div>
without seeing attempt @ implementing spec(s) or stack trace of failed attempt, refer following articles/resources started on unit testing directives:
- https://docs.angularjs.org/guide/unit-testing
- http://angular-tips.com/blog/2014/06/introduction-to-unit-test-directives/
- http://www.benlesh.com/2013/06/angular-js-unit-testing-directives.html
- https://github.com/vojtajina/ng-directive-testing
- http://www.sitepoint.com/angular-testing-tips-testing-directives/
- http://blog.revolunet.com/blog/2013/12/05/unit-testing-angularjs-directive/
- https://egghead.io/lessons/angularjs-unit-testing-a-directive
the rough basics:
- inject module spec suite.
- $compile directive template.
- store $compiled directive variable, available of individual specs.
- trigger
.isolatescope().$digest. - write expectations.
Comments
Post a Comment