Open hovissimo opened 5 years ago
I found this too, it looks like the README is misleading.
For me, the following syntax works
expect(props.togglePurchasable).to.have.been.always.calledWithExactly(props.purchasable.id);
I think the README is correct, but it's perhaps not totally obvious unless you read the right-hand side of the table more closely. Here are just the relevant rows from the README:
Sinon.JS property/method | Sinon–Chai assertion |
---|---|
alwaysCalledWithNew | spy.should.always.have.been.calledWithNew |
alwaysCalledWith | spy.should.always.have.been.calledWith(...args) |
alwaysCalledWithExactly | spy.should.always.have.been.calledWithExactly(...args) |
alwaysCalledWithMatch | spy.should.always.have.been.calledWithMatch(...args) |
alwaysReturned | spy.should.have.always.returned(returnVal) |
alwaysThrew | spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing) |
The correct sinon-chai
assertion is listed in the right-hand column, so I imagine this issue is from quickly skimming the table and trying to use the name in the left-hand column. That's understandable since always
and not
are the only cases where the method name is not just tacked on the end, but it of course won't work.
I've opened #153 to add a clarifying note to call this out, I think that's about all that is to be done here.
My error:
(...).to.have.been.alwaysCalledWith is not a function
My code
My versions: chai: 3.5.0 sinon:7.2.2 sinon-chai:3.3.0
I get the same result when I try to use
alwaysCalledWith
, but I don't have any problem usingcalledWith
orcalledWithExactly
(except of course that they're not the assertion I need).I noticed that
alwaysCalledWith
andalwaysCalledWithExactly
are missing from the bottom of lib/sinon-chai.js, is this a coincidence?alwaysCalledWith
andalwaysCalledWithExactly
are listed in the README, so I assume they should be available.https://github.com/domenic/sinon-chai/blob/fb4f82a684db5aad277163943ae4c6732b5d7a22/lib/sinon-chai.js#L131-L148