AngularJS - how to unit test directive that has no logic in it -


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:


the rough basics:

  • inject module spec suite.
  • $compile directive template.
  • store $compiled directive variable, available of individual specs.
  • trigger .isolatescope().$digest.
  • write expectations.

Comments