title: AngularJs : triggering an event to simulate user action when unit testing a directive
body: <p>I have seen that in order to simulate user action on the DOM generated by a directive, there are two approaches, both trigering an event:</p>
  
  <p><a href="https://stackoverflow.com/questions/17626604/how-to-trigger-ng-change-in-directive-test-in-angularjs">How to trigger ng-change in directive test in AngularJS</a></p>
  
  <p>The first approach uses jquery and the second one a function called <strong>browserTrigger</strong> defined in <strong>angular-scenario.js</strong>. The second one is supposed to be better as jquery would have a bug on event triggering (which I believe, I am not arguing :) ).</p>
  
  <p>Using the angular-scenario means e2e testing for me. but I have seen <a href="http://egghead.io/lessons/angularjs-unit-testing-directive-scope" rel="nofollow noreferrer">egghead video</a>  and he seems to do unit testing. How is this possible ?</p>
  
  <p>I guess he just copied the function ?</p>
  
  <p>I think I am going to test directives as e2e tests, it makes more sense as unit test is more fore pure functions.</p>
  
  <hr>
  
  <p>Well, I just found that browserTrigger is something internal not supposed to be used directly : <a href="https://github.com/angular/angular.js/issues/5178" rel="nofollow noreferrer">https://github.com/angular/angular.js/issues/5178</a></p>
  
  <hr>
  
  <p>Thanks!</p>