Skip to content

Commit

Permalink
add spy.reset method and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d48 committed Jul 7, 2015
1 parent d881adf commit 381511d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,23 @@ module.exports = function (chai, _) {
s += " }";
return s;
};
proxy.__spy = {

/**
* # proxy.reset (function)
*
* Resets __spy object parameters for instantiation and reuse
* @returns proxy spy object
*/
proxy.reset = function() {
this.__spy = {
calls: []
, called: false
, name: name
};
, called: false
, name: name
};
return this;
}

return proxy;
return proxy.reset();
}

/**
Expand Down
30 changes: 30 additions & 0 deletions test/spies.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,34 @@ describe('Chai Spies', function () {
object.push().should.equal('push');
});
});

describe('reset method', function() {
it('should reset spy object values to defaults when called', function() {
var name = 'proxy';
var spy = chai.spy(name);

spy();
spy.should.have.been.called();
spy.__spy.called.should.be.true;
spy.__spy.calls.should.have.length(1);
spy.__spy.name.should.be.equal(name);

spy.reset();

spy.should.not.have.been.called();
spy.__spy.called.should.be.false;
spy.__spy.calls.should.have.length(0);
spy.__spy.name.should.be.equal(name);
});

it('should setup spy with default values when spy is instantiated', function() {
var name = 'proxy';
var spy = chai.spy(name);

spy.should.be.spy;
spy.__spy.called.should.be.false;
spy.__spy.calls.should.have.length(0);
spy.__spy.name.should.be.equal(name);
});
});
});

0 comments on commit 381511d

Please sign in to comment.