title: How to trigger window.onbeforeunload in jasmine test
body: <p>Currently, I have created a directive attached to a form. Anytime the form is dirty, I have a confirmation modal by window.onbeforeunload pop up when trying to leave. Right now I'm trying to write a jasmine test to make sure window.onbeforeunload gets called upon refresh/url change.</p>
  
  <pre><code>var app = angular.directive('app');
  
  app.directive('dialog',[$window, function() {
      return {
          restrict: 'A',
          require: 'form',
          link: function(scope, element, attrs, formCtrl) {
              $window.onbeforeunload = function () {
                  if(formCtrl.$dirty) {
                      return 'Are you sure you want to leave this form';
                  }
              };
          }
      };
  }]);
  </code></pre>
  
  <p>Part of the Jasmine Spec  </p>
  
  <pre><code>beforeEach(inject(function(_$rootScope_,_$state_,_$window_) {
      $rootScope = _$rootScope_;
      $state = _$state_;
      $window = _$window_;
  
      spyOn($window, 'onbeforeunload')
  }));
  
  describe('Listen for window prompt', function () {
      it('should be called on url/refresh change', function () {
          window.location.reload();
          expect($window.onbeforeunload).toHaveBeenCalled();
      });
  });
  </code></pre>