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

sinon v11 broke sinon.match assertions on your mock #24

Closed
m-ronchi opened this issue May 28, 2021 · 4 comments
Closed

sinon v11 broke sinon.match assertions on your mock #24

m-ronchi opened this issue May 28, 2021 · 4 comments

Comments

@m-ronchi
Copy link

your package depends on sinon v9, that depends on @sinonjs/samsam v5 (the package used to implement matchers)

sinon released v11 that depends on @sinonjs/samsam v6.
installing sinon v11 in my project together with aws-sdk-client-mock results in duplicates of both packages installed, thus breaking tests with assertions like this:

sinon.assert.calledWithExactly(s3mock.send, sinon.match.any)

you should either:

  • upgrade to sinon v11
  • move sinon to peer dependencies to not duplicate it
  • expose sinon.match* through your package
m-radzikowski added a commit that referenced this issue May 31, 2021
* chore: bump sinon to v11 (fixes #24)

* fix: move sinon types to prod dependencies (fixes #22)
@m-radzikowski
Copy link
Owner

Thanks for the info. I've updated Sinon to v11 in the latest v0.5.0.

I think peer dependencies would not work here as the lib uses Sinon itself.
I don't want to expose matchers by myself to allow easy usage with regular Sinon. But I will reconsider if it will be a problem in the future.

@m-ronchi
Copy link
Author

m-ronchi commented Apr 5, 2022

this broke again with sinon@13

@m-radzikowski
Copy link
Owner

@m-ronchi can you create a repo with minimal reproduction, please? And provide npm / yarn version with it.

My quick test with npm 8.5.3 and yarn 1.22.17 worked well.

In package.json:

  "dependencies": {
    "@aws-sdk/client-sns": "3.32.0"
  },
  "devDependencies": {
    "sinon": "13.0.1",
    "@types/sinon": "9.0.10",
    "@aws-sdk/types": "3.32.0"
  }

test:

import {assert, match} from 'sinon';
import {mockClient} from 'aws-sdk-client-mock';
import {PublishCommand, SNSClient} from '@aws-sdk/client-sns';

const snsMock = mockClient(SNSClient);

beforeEach(() => {
    snsMock.reset();
});

it('works with sinon', async () => {
    const sns = new SNSClient({});

    await sns.send(new PublishCommand({TopicArn: 'my:topic', Message: 'msg'}));

    assert.calledWithExactly(snsMock.send, match.any);
})

sinon version installed at node_modules root is the one from the package.json (13.0.1).

@m-ronchi
Copy link
Author

m-ronchi commented Apr 6, 2022

sorry, it turned out that @aws-sdk/lib-storage changed the underlying calls from MultipartUpload to PutObject when I upgraded (a minor) and at the time I found duplicated sinon v11/v13 in my node_modules.

the error message was confusing AF

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

2 participants