Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alwaysCalledWithExactly is not a function #139

Open
hovissimo opened this issue Jan 30, 2019 · 2 comments
Open

alwaysCalledWithExactly is not a function #139

hovissimo opened this issue Jan 30, 2019 · 2 comments

Comments

@hovissimo
Copy link

My error: (...).to.have.been.alwaysCalledWith is not a function

My code

 it("fires props.togglePurchasable with id when clicked", function() {                     
   const props = cloneDeep(baseProps);                                                     
                                                                                           
   const wrapper = shallow(<StoreFrontPurchasable {...props} />);                          
                                                                                           
   wrapper.find("button").simulate("click");                                               
   wrapper.find("button").simulate("click");                                               
   wrapper.find("button").simulate("click");                                               
                                                                                           
   expect(props.togglePurchasable.callCount).to.equal(3);                                  
   expect(props.togglePurchasable).to.have.been.alwaysCalledWithExactly(props.purchasable.id);    
 });                                                                                       

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 using calledWith or calledWithExactly (except of course that they're not the assertion I need).

I noticed that alwaysCalledWith and alwaysCalledWithExactly are missing from the bottom of lib/sinon-chai.js, is this a coincidence? alwaysCalledWith and alwaysCalledWithExactly 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

@doughive
Copy link

doughive commented Aug 5, 2019

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);

cincodenada added a commit to cincodenada/sinon-chai that referenced this issue Nov 2, 2021
This is the only instance (besides the `not` methods) where we don't just tack the method name on the end, so it seems worth a call-out, as it has already confused at least two people per chaijs#139
@cincodenada
Copy link
Contributor

cincodenada commented Nov 2, 2021

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.

simondel pushed a commit that referenced this issue Apr 29, 2022
This is the only instance (besides the `not` methods) where we don't just tack the method name on the end, so it seems worth a call-out, as it has already confused at least two people per #139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants