+ Reply to Thread
Results 1 to 2 of 2

Thread: Clearing a spy on jasmine

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    31

    Clearing a spy on jasmine

    How do i clear the spy in a jasmine test suite ?
    Code:
    beforeEach(function() {
      spyOn($, "ajax").andCallFake(function(params){
      })
    })
    
    it("do something", function() {
    })

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    41
    You can use an ispy flag :
    Code:
    describe('test', function() {
        var a = {b: function() {
        }};
        beforeEach(function() {
            spyOn(a, 'b').andCallFake(function(params) {
                return 'spy1';
            })
        })
        it('should return spy1', function() {
            expect(a.b()).toEqual('spy1');
        })
    
        it('should return spy2', function() {
            a.b.isSpy = false;
            spyOn(a, 'b').andCallFake(function(params) {
                return 'spy2';
            })
            expect(a.b()).toEqual('spy2');
        })
    
    })

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts