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.

sinonProperty("called", "been called", " at least once, but it was never called");
sinonPropertyAsBooleanMethod("callCount", "been called exactly %1", ", but it was called %c%C");
sinonProperty("calledOnce", "been called exactly once", ", but it was called %c%C");
sinonProperty("calledTwice", "been called exactly twice", ", but it was called %c%C");
sinonProperty("calledThrice", "been called exactly thrice", ", but it was called %c%C");
sinonMethodAsProperty("calledWithNew", "been called with new");
sinonMethod("calledBefore", "been called before %1");
sinonMethod("calledAfter", "been called after %1");
sinonMethod("calledImmediatelyBefore", "been called immediately before %1");
sinonMethod("calledImmediatelyAfter", "been called immediately after %1");
sinonMethod("calledOn", "been called with %1 as this", ", but it was called with %t instead");
sinonMethod("calledWith", "been called with arguments %*", "%D");
sinonMethod("calledOnceWith", "been called exactly once with arguments %*", "%D");
sinonMethod("calledWithExactly", "been called with exact arguments %*", "%D");
sinonMethod("calledOnceWithExactly", "been called exactly once with exact arguments %*", "%D");
sinonMethod("calledWithMatch", "been called with arguments matching %*", "%D");
sinonMethod("returned", "returned %1");
exceptionalSinonMethod("thrown", "threw", "thrown %1");

@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 domenic#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