title: How to spy on anonymous function using Jasmine
body: <p>I'm using Jasmine to test my angular application and want to spy on an anonymous function.
  Using angular-notify service <a href="https://github.com/cgross/angular-notify" rel="noreferrer">https://github.com/cgross/angular-notify</a>, I want to know whether notify function have been called or not.</p>
  
  <p>Here is my controller:</p>
  
  <pre><code>angular.module('module').controller('MyCtrl', function($scope, MyService, notify) {
  
    $scope.isValid = function(obj) {
      if (!MyService.isNameValid(obj.name)) {
        notify({ message:'Name not valid', classes: ['alert'] });
        return false;
      }
    }
  });
  </code></pre>
  
  <p>And here is my test:</p>
  
  <pre><code>'use strict';
  
  describe('Test MyCtrl', function () {
    var scope, $location, createController, controller, notify;
  
    beforeEach(module('module'));
  
    beforeEach(inject(function ($rootScope, $controller, _$location_, _notify_) {
      $location = _$location_;
      scope = $rootScope.$new();
      notify = _notify_;
  
      notify = jasmine.createSpy('spy').andReturn('test');
  
      createController = function() {
        return $controller('MyCtrl', {
          '$scope': scope
        });
      };
    }));
  
    it('should call notify', function() {
      spyOn(notify);
      controller = createController();
      scope.isValid('name');
      expect(notify).toHaveBeenCalled();
    });
  });
  </code></pre>
  
  <p>An obviously return :</p>
  
  <pre><code>Error: No method name supplied on 'spyOn(notify)'
  </code></pre>
  
  <p>Because it should be something like spyOn(notify, 'method'), but as it's an anonymous function, it doesn't have any method.</p>
  
  <p>Thanks for your help.</p>