How do we clear spy programmatically in Jasmine?

后端 未结 10 2448
孤独总比滥情好
孤独总比滥情好 2020-12-15 02:11

How do we clear the spy in a jasmine test suite programmatically? Thanks.

beforeEach(function() {
  spyOn($, \"ajax\").andCallFake(function(params){
  })
})
         


        
10条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 02:51

    I think that's what .reset() is for:

    spyOn($, 'ajax');
    
    $.post('http://someUrl', someData);
    
    expect($.ajax).toHaveBeenCalled();
    
    $.ajax.calls.reset()
    
    expect($.ajax).not.toHaveBeenCalled();
    

提交回复
热议问题