How to spy on anonymous function using Jasmine

前端 未结 2 2026
长发绾君心
长发绾君心 2021-02-10 04:56

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:08

    Daniel Smink's answer is correct, but note that the syntax has changed for Jasmine 2.0.

    notify = jasmine.createSpy().and.callFake(function() {
      return false;
    });
    

    I also found it useful to just directly return a response if you only need a simple implementation

    notify = jasmine.createSpy().and.returnValue(false);
    

提交回复
热议问题