Skip to content

calledOnceWith & calledOnceWithExactly sinon matchers missing #9644

Closed
@Andarist

Description

@Andarist

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

Activity

jennifer-shehane

jennifer-shehane commented on Dec 14, 2020

@jennifer-shehane
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

sainthkh commented on Dec 15, 2020

@sainthkh
Contributor

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:

  • The new version of cypress-io/sinon-chai should be released.
    Update @cypress/sinon-chai dependency.
sainthkh

sainthkh commented on Dec 30, 2020

@sainthkh
Contributor

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

jennifer-shehane

jennifer-shehane commented on Dec 30, 2020

@jennifer-shehane
Member

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

jennifer-shehane

jennifer-shehane commented on Dec 30, 2020

@jennifer-shehane
Member

@sainthkh It's been released as 2.9.1

cypress-bot

cypress-bot commented on Jan 4, 2021

@cypress-bot
Contributor

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.

3 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: typingsIssue related to Cypress types (for TypeScript)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jennifer-shehane@sainthkh@Andarist

      Issue actions

        calledOnceWith & calledOnceWithExactly sinon matchers missing · Issue #9644 · cypress-io/cypress