How to spy on anonymous function using Jasmine

前端 未结 2 558
借酒劲吻你
借酒劲吻你 2021-02-10 04:35

I\'m using Jasmine to test my angular application and want to spy on an anonymous function. Using angular-notify service https://github.com/cgross/angular-notify, I want to know

2条回答
  •  独厮守ぢ
    2021-02-10 05:21

    You could chain your spy with andCallFake see:

    http://jasmine.github.io/1.3/introduction.html#section-Spies:_andCallFake

        //create a spy and define it to change notify
        notify = jasmine.createSpy().andCallFake(function() {
          return false;
        });
    
        it('should be a function', function() {
            expect(typeof notify).toBe('function');             
        });
    
        controller = createController();
        scope.isValid('name');
        expect(notify).toHaveBeenCalled();
    

提交回复
热议问题