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

calledOnceWith & calledOnceWithExactly sinon matchers missing #9644

Closed
Andarist opened this issue Dec 11, 2020 · 7 comments · Fixed by #14371
Closed

calledOnceWith & calledOnceWithExactly sinon matchers missing #9644

Andarist opened this issue Dec 11, 2020 · 7 comments · Fixed by #14371
Labels
type: typings Issue related to Cypress types (for TypeScript)

Comments

@Andarist
Copy link
Contributor

Current behavior

CypressError: The chainer calledOnceWith was not found. Could not build assertion.

But TS types define this as allowed:

(chainer: 'be.calledOnceWith' | 'have.been.calledOnceWith', ...args: any[]): Chainable<Subject>

(chainer: 'be.calledOnceWithExactly' | 'have.been.calledOnceWithExactly', ...args: any[]): Chainable<Subject>

Desired behavior

Working matcher

Description

I've even started looking into fixing this but this seems to be over my head in a timeframe that I could spend on this right now.

It's not obvious to track what version are you even using because you rely on npm hoisting - your packages define very different versions of chai, sinon, chai-sinon & @cypress/chai-sinon. I believe that it would be great to:

  • unify those versions
  • provide at least a peer dep range where applicable

From what I've analyzed you are actually using your @cypress/chai-sinon fork in the Cypress' public API:

const sinonChai = require('@cypress/sinon-chai')

and the driver package requires the v1 of that fork package, but only in its dev dep:
"@cypress/sinon-chai": "1.1.0",

so in reality a different version gets probably loaded at runtime in the final product.

At the same time, your fork is already at v2 and it just doesn't really add those methods to the expect object. The only ones that are handled are listed here:
https://github.com/cypress-io/sinon-chai/blob/3af9baa3b2981db8ade653bcbff58da1a1094a32/lib/sinon-chai.js#L174

Additionally links to the Sinon docs in the JSDOCs above types for all sinon-chai method are pointing to Sinon v4 docs but I also don't believe this is actually a version that is used. Note that you link to different methods above those 2 missing methods because they have not been implemented in Sinon v4.

Test code to reproduce

const foo = cy.spy().as("foo")

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

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

Versions

6.1.0

@jennifer-shehane jennifer-shehane added the type: typings Issue related to Cypress types (for TypeScript) label Dec 14, 2020
@jennifer-shehane
Copy link
Member

Yeah, the versions of each packages may be a bit off. I think @sainthkh may have been the last person to really play with the sinon typings, maybe he has some ideas.

@sainthkh
Copy link
Contributor

sainthkh commented Dec 15, 2020

Confirmed the bug. I added them mechanically from the sinon documentation and didn't test them and thought they would naturally work. But I was wrong.

Things to do:

@sainthkh
Copy link
Contributor

Can anyone release the next version of @cypress/sinon-chai? It's blocking this issue from closing.

@jennifer-shehane
Copy link
Member

Oh. Yah, we merged in the PR. Thought it would auto release 🤔

@jennifer-shehane
Copy link
Member

@sainthkh It's been released as 2.9.1

@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] and removed stage: needs investigating Someone from Cypress needs to look at this labels Dec 31, 2020
@cypress-bot cypress-bot bot added stage: pending release There is a closed PR for this issue and removed stage: work in progress There is an open PR for this issue [WIP] labels Jan 4, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 4, 2021

The code for this is done in cypress-io/cypress#14371, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 4, 2021

Released in 6.2.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v6.2.1, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label Jan 4, 2021
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jan 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: typings Issue related to Cypress types (for TypeScript)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants