chaijs/sinon-chai

Sinon-chai ignoring the lastCall property on spy

Kilometers42 opened this issue · 1 comments

It looks like sinon-chai is ignoring lastCall property on a spy inside an expect. For example:
expect(spy.lastCall).to.have.been.calledWith(argUsedOnLastCall)
sinon-chai ignores the lastCall property and does the same thing that it would do with this line:
expect(spy).to.have.been.calledWith(argUsedOnLastCall)
where it checks argUsedOnLastCall against all the calls that have been made with that spy. However, if you were to do this in pure sinon it behaves correctly: sinon.assert.calledWith(lastCall, argUsedOnLastCall) and checks argUsedOnLastCall only against the last call of the spy.

Cannot reproduce:

"use strict";

const sinon = require("sinon");
const chai = require("chai");

const expect = chai.expect;
chai.should();

const sinonChai = require("sinon-chai");
chai.use(sinonChai);

const spy = sinon.spy();

spy(1, 2, 3);
spy(4, 5, 6);


expect(() => spy.lastCall.should.have.been.calledWith(4, 5, 6)).to.not.throw()

Will close for now, but happy to reopen if you can provide a repro case like this.