How do we clear spy programmatically in Jasmine?

后端 未结 10 2386
孤独总比滥情好
孤独总比滥情好 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

    Or you can do it

    describe('test', function() {
        var a, c;
        c = 'spy1';
        a = {
          b: function(){}
        };
    
        beforeEach(function() {
            spyOn(a, 'b').and.callFake(function () {
                 return c;
            });
        })
    
        it('should return spy1', function() {
            expect(a.b()).toEqual('spy1');
        })
    
        it('should return spy2', function() {
            c = 'spy2';
            expect(a.b()).toEqual('spy2');
        })
    
    })

    In this case you use the same Spy but just change the var that it will return..

提交回复
热议问题