{"name":"sinon-chai","type":"module","description":"Extends Chai with assertions for the Sinon.JS mocking framework.","keywords":["chai","chai-plugin","browser","vendor","mocks-and-spies","sinon","testing","spies","stubs","mocks"],"version":"4.0.1","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"contributors":[{"name":"Simon de Lang","email":"simondelang@gmail.com"}],"license":"(BSD-2-Clause OR WTFPL)","repository":{"type":"git","url":"git+https://github.com/chaijs/sinon-chai.git"},"main":"./lib/sinon-chai.js","exports":{".":"./lib/sinon-chai.js"},"scripts":{"test":"c8 mocha","test-ci":"npm install && npm install chai@$CHAI_VERSION && npm install sinon@$SINON_VERSION && npm test","lint":"eslint .","format":"prettier --write lib"},"peerDependencies":{"chai":"^5.0.0 || ^6.0.0","sinon":">=4.0.0"},"devDependencies":{"@eslint/js":"^9.7.0","c8":"^10.1.2","chai":"^5.0.0","eslint":"^8.57.0","mocha":"^10.7.0","prettier":"^3.3.3","sinon":"^9.0.0"},"_id":"sinon-chai@4.0.1","gitHead":"64cd19a7b4fdc0e8a48c49e64c6c4169ba8d4ac2","bugs":{"url":"https://github.com/chaijs/sinon-chai/issues"},"homepage":"https://github.com/chaijs/sinon-chai#readme","_nodeVersion":"22.18.0","_npmVersion":"11.5.2","dist":{"integrity":"sha512-xMKEEV3cYHC1G+boyr7QEqi80gHznYsxVdC9CdjP5JnCWz/jPGuXQzJz3PtBcb0CcHAxar15Y5sjLBoAs6a0yA==","shasum":"f70000fe0e4f4ab7ceeb3703d3053f8886e0386b","tarball":"http://registry-npm.ywwl.com/sinon-chai/download/sinon-chai-4.0.1.tgz","fileCount":4,"unpackedSize":15195,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/sinon-chai@4.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCck8UgBjOb8fKQyNVA8XIGA4yRCtkqHVJI6B7YsHVgpAIgfA/5kGuFV0AdMDhtXstip9jVPaN2eV2/y++g3jyw9iY="}],"size":4832,"noattachment":false,"key":"/sinon-chai/-/sinon-chai-4.0.1.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:e15bf2f2-8bc2-4485-998b-feb996f4e353"}},"directories":{},"maintainers":[{"name":"domenic","email":"d@domenic.me"},{"name":"chaijs","email":"chaijs@keithcirkel.co.uk"},{"name":"simondel","email":"simondelang@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sinon-chai_4.0.1_1755860538831_0.09036737091973657"},"_hasShrinkwrap":false,"readme":"# Sinon.JS Assertions for Chai\n\n**Sinon–Chai** provides a set of custom assertions for using the [Sinon.JS][] spy, stub, and mocking framework with the\n[Chai][] assertion library. You get all the benefits of Chai with all the powerful tools of Sinon.JS.\n\nInstead of using Sinon.JS's assertions:\n\n```javascript\nsinon.assert.calledWith(mySpy, \"foo\");\n```\n\nor awkwardly trying to use Chai's `should` or `expect` interfaces on spy properties:\n\n```javascript\nmySpy.calledWith(\"foo\").should.be.ok;\nexpect(mySpy.calledWith(\"foo\")).to.be.ok;\n```\n\nyou can say\n\n```javascript\nmySpy.should.have.been.calledWith(\"foo\");\nexpect(mySpy).to.have.been.calledWith(\"foo\");\n```\n\n## Assertions\n\nAll of your favorite Sinon.JS assertions made their way into Sinon–Chai. We show the `should` syntax here; the `expect`\nequivalent is also available.\n\n| Sinon.JS property/method | Sinon–Chai assertion                                              |\n|--------------------------|-------------------------------------------------------------------|\n| called                   | spy.should.have.been.called                                       |\n| callCount                | spy.should.have.callCount(n)                                      |\n| calledOnce               | spy.should.have.been.calledOnce                                   |\n| calledTwice              | spy.should.have.been.calledTwice                                  |\n| calledThrice             | spy.should.have.been.calledThrice                                 |\n| calledBefore             | spy1.should.have.been.calledBefore(spy2)                          |\n| calledAfter              | spy1.should.have.been.calledAfter(spy2)                           |\n| calledImmediatelyBefore  | spy.should.have.been.calledImmediatelyBefore(spy2)                |\n| calledImmediatelyAfter   | spy.should.have.been.calledImmediatelyAfter(spy2)                 |\n| calledWithNew            | spy.should.have.been.calledWithNew                                |\n| alwaysCalledWithNew      | spy.should.always.have.been.calledWithNew                         |\n| calledOn                 | spy.should.have.been.calledOn(context)                            |\n| alwaysCalledOn           | spy.should.always.have.been.calledOn(context)                     |\n| calledWith               | spy.should.have.been.calledWith(...args)                          |\n| alwaysCalledWith         | spy.should.always.have.been.calledWith(...args)                   |\n| calledOnceWith           | spy.should.always.have.been.calledOnceWith(...args)               |\n| calledWithExactly        | spy.should.have.been.calledWithExactly(...args)                   |\n| alwaysCalledWithExactly  | spy.should.always.have.been.calledWithExactly(...args)            |\n| calledOnceWithExactly    | spy.should.always.have.been.calledOnceWithExactly(...args)        |\n| calledWithMatch          | spy.should.have.been.calledWithMatch(...args)                     |\n| alwaysCalledWithMatch    | spy.should.always.have.been.calledWithMatch(...args)              |\n| returned                 | spy.should.have.returned(returnVal)                               |\n| alwaysReturned           | spy.should.have.always.returned(returnVal)                        |\n| threw                    | spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing)        |\n| alwaysThrew              | spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing) |\n\nFor more information on the behavior of each assertion, see\n[the documentation for the corresponding spy methods][spymethods]. These of course work on not only spies, but\nindividual spy calls, stubs, and mocks as well.\n\nNote that you can negate any assertion with Chai's `.not`. E. g. for `notCalled` use `spy.should.have.not.been.called`. Similarly, note that the `always` methods are accessed with Chai's `.always` prefix; `should.have.been.alwaysCalledWith` will not work - instead, use `should.always.have.been.calledWith`.\n\nFor simplicity, this library intentionally only implements Sinon's spy methods, and does not add an interface for `Sinon.assert.match`. Sinon's matchers are implemented by the `samsam` library, so if you want a should/expect interface to `assert.match` you may be interested in [chai-samsam](https://www.chaijs.com/plugins/chai-samsam/), which adds a `.deep.match` verb that will work with Sinon matchers.\n\nFor `assert` interface there is no need for `sinon-chai` or `chai-samsam`. You can install [Sinon.JS assertions][sinonassertions] right into Chai's `assert` object with `expose`:\n\n```javascript\nimport * as chai from \"chai\";\nimport sinon from \"sinon\";\n\nsinon.assert.expose(chai.assert, { prefix: \"\" });\n```\n\n## Examples\n\nUsing Chai's `should`:\n\n```javascript\n\"use strict\";\nimport * as chai from \"chai\";\nimport sinon from \"sinon\";\nimport sinonChai from \"sinon-chai\";\nchai.should();\nchai.use(sinonChai);\n\nfunction hello(name, cb) {\n    cb(\"hello \" + name);\n}\n\ndescribe(\"hello\", function () {\n    it(\"should call callback with correct greeting\", function () {\n        var cb = sinon.spy();\n\n        hello(\"foo\", cb);\n\n        cb.should.have.been.calledWith(\"hello foo\");\n    });\n});\n```\n\nUsing Chai's `expect`:\n\n```javascript\n\"use strict\";\nimport * as chai from \"chai\";\nimport sinon from \"sinon\";\nimport sinonChai from \"sinon-chai\";\nconst expect = chai.expect;\nchai.use(sinonChai);\n\nfunction hello(name, cb) {\n    cb(\"hello \" + name);\n}\n\ndescribe(\"hello\", function () {\n    it(\"should call callback with correct greeting\", function () {\n        var cb = sinon.spy();\n\n        hello(\"foo\", cb);\n\n        expect(cb).to.have.been.calledWith(\"hello foo\");\n    });\n});\n```\n\n## Installation and Usage\n\n### Node\n\nDo an `npm install --save-dev sinon-chai` to get up and running. Then:\n\n```javascript\nimport * as chai from \"chai\";\nimport sinonChai from \"sinon-chai\";\n\nchai.use(sinonChai);\n```\n\nYou can of course put this code in a common test fixture file; for an example using [Mocha][], see\n[the Sinon–Chai tests themselves][fixturedemo].\n\n### Ruby on Rails\n\nThanks to [Cymen Vig][], there's now [a Ruby gem][] of Sinon–Chai that integrates it with the Rails asset pipeline!\n\n[Sinon.JS]: http://sinonjs.org/\n[Chai]: http://chaijs.com/\n[spymethods]: http://sinonjs.org/docs/#spies-api\n[sinonassertions]: http://sinonjs.org/docs/#assertions\n[Mocha]: https://mochajs.org/\n[fixturedemo]: https://github.com/domenic/sinon-chai/tree/master/test/\n[AMD]: https://github.com/amdjs/amdjs-api/wiki/AMD\n[Cymen Vig]: https://github.com/cymen\n[a Ruby gem]: https://github.com/cymen/sinon-chai-rails\n","publish_time":1755860539034,"_cnpm_publish_time":1755860539034,"dist-tags":{"latest":"4.0.1","next":"4.0.0-0"}}