jasmine - AngularJS how to unit test to ensure directives like ng-click point to valid code -


i'm using jasmine write unit tests our controllers, wanted community feedback on how handle situation...

i have controller - invoicecontroller, this:

angular.module('mymodule').controller('mycontroller', ['$scope',     function($scope) {         $scope.dosomething = function() {             $scope.something = 'bar';         };     } ]}); 

in unit tests verify controller has expected methods:

it('should able work', function() {      // initialize scope properties     scope.someproperty = 'foo';      // load controller using properties     injectcontroller();      // have of functions necessary work?     expect(typeof (scope.dosomething)).tobe('function');      // execute test     scope.dosomething();     expect(scope.something).tobe('bar');         } 

and finally, in html have element ng-click, this:

<button ng-click="dosomehing()">do something</button> 

looks good, right? but, did catch did wrong?

my ng-click method misspelled, tests green , life seems rosy...until try click on guy , nothing happens. no render time error, no error on click. hmm.

several times i'm refactoring code has got me. rename dosomething dosomethingcooler in unit test , in controller miss place in html. after minute of head scratching see missed.

i'd love way ensure markup valid. e2e tests seem obvious solution, prone fragility hoping there alternatives.

if asp.net attach click events code behind compile time errors vs run time errors.

thoughts??

thad

one thing template text , run $compile on it. , link controller's scope. dom.find('[ng-click]').click();, should throw if of them not defined in controller's scope. similar how test directives.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -