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

fix(sinon-chai): Added once commands for sinon methods #46

Merged
merged 1 commit into from
Dec 23, 2020

Conversation

sainthkh
Copy link

@@ -181,7 +181,9 @@
sinonMethod("calledAfter", "been called after %1");
sinonMethod("calledOn", "been called with %1 as this", "", ", but it was called with %t instead");
sinonMethod("calledWith", "been called with arguments %*");
sinonMethod("calledOnceWith", "been called exactly once with arguments %*");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering - shouldnt this report an error based on a failed criteria? The user wont easily know now if the function has been called more than once or if it has been called with wrong arguments

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I manually tested them. Users can know if a function is called more than once or with wrong arguments.

  • Called more than once:

Code:

it('t', () => {
  const foo = cy.spy().as('foo')

  setTimeout(() => {
    foo({ bar: 'test' })
    foo({ bar: 'test' })
  }, 500)

  cy.get('@foo').should(
    'be.calledOnceWith',
    Cypress.sinon.match({
      bar: 'test',
    }),
  )
})

Result:
Screenshot from 2020-12-15 16-02-20

  • Wrong arguments:

Code:

it('t', () => {
  const foo = cy.spy().as('foo')

  setTimeout(() => {
    foo({ bar: 'testing' })
  }, 500)

  cy.get('@foo').should(
    'be.calledOnceWith',
    Cypress.sinon.match({
      bar: 'test',
    }),
  )
})

Result:
Screenshot from 2020-12-15 16-03-58

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this addresses my concerns - although I believe that the first part of the error message could be more clear about what has failed. One has to deduce it from the "following calls were made" part. Having the Cypress.sinon.match object stringified in a way it is stringified doesn't help much either.

@jennifer-shehane jennifer-shehane changed the title Added once commands. fix: Added once commands. Dec 15, 2020
@jennifer-shehane jennifer-shehane changed the title fix: Added once commands. fix: Added once commands for sinon methods Dec 15, 2020
@jennifer-shehane jennifer-shehane changed the title fix: Added once commands for sinon methods fix(sinon-chai): Added once commands for sinon methods Dec 15, 2020
@chrisbreiding chrisbreiding merged commit b96b566 into cypress-io:master Dec 23, 2020
@bahmutov
Copy link

🎉 This PR is included in version 2.9.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants