{"name":"sinon-chai","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":"3.7.0","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/domenic/sinon-chai.git"},"main":"./lib/sinon-chai.js","scripts":{"test":"mocha","test-travis":"npm install && npm install chai@$CHAI_VERSION && npm install sinon@$SINON_VERSION && npm test","lint":"eslint .","cover":"nyc --reporter=html mocha && opener ./coverage/sinon-chai.js.html"},"peerDependencies":{"chai":"^4.0.0","sinon":">=4.0.0"},"devDependencies":{"chai":"^4.2.0","eslint":"^6.8.0","mocha":"^7.0.1","nyc":"^15.0.0","opener":"^1.5.1","sinon":"^9.0.0"},"gitHead":"74a1bc0d5b9518341f255bf771c15bddff97664e","bugs":{"url":"https://github.com/domenic/sinon-chai/issues"},"homepage":"https://github.com/domenic/sinon-chai#readme","_id":"sinon-chai@3.7.0","_nodeVersion":"14.16.0","_npmVersion":"7.6.0","dist":{"shasum":"cfb7dec1c50990ed18c153f1840721cf13139783","size":5237,"noattachment":false,"tarball":"https://registry.npmmirror.com/sinon-chai/-/sinon-chai-3.7.0.tgz","integrity":"sha512-mf5NURdUaSdnatJx3uhoBOrY9dtL19fiOtAdT1Azxg3+lNJFiuN0uzaU3xX1LeAfL17kHQhTAJgpsfhbMJMY2g=="},"_npmUser":{"name":"simondel","email":"simondelang@gmail.com"},"directories":{},"maintainers":[{"name":"simondel","email":"simondelang@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sinon-chai_3.7.0_1621941765200_0.7836784143725462"},"_hasShrinkwrap":false,"publish_time":1621941765315,"_cnpm_publish_time":1621941765315,"_cnpmcore_publish_time":"2021-12-14T05:39:19.642Z","readme":"# Sinon.JS Assertions for Chai\r\n\r\n**Sinon–Chai** provides a set of custom assertions for using the [Sinon.JS][] spy, stub, and mocking framework with the\r\n[Chai][] assertion library. You get all the benefits of Chai with all the powerful tools of Sinon.JS.\r\n\r\nInstead of using Sinon.JS's assertions:\r\n\r\n```javascript\r\nsinon.assert.calledWith(mySpy, \"foo\");\r\n```\r\n\r\nor awkwardly trying to use Chai's `should` or `expect` interfaces on spy properties:\r\n\r\n```javascript\r\nmySpy.calledWith(\"foo\").should.be.ok;\r\nexpect(mySpy.calledWith(\"foo\")).to.be.ok;\r\n```\r\n\r\nyou can say\r\n\r\n```javascript\r\nmySpy.should.have.been.calledWith(\"foo\");\r\nexpect(mySpy).to.have.been.calledWith(\"foo\");\r\n```\r\n\r\n## Assertions\r\n\r\nAll of your favorite Sinon.JS assertions made their way into Sinon–Chai. We show the `should` syntax here; the `expect`\r\nequivalent is also available.\r\n\r\n| Sinon.JS property/method | Sinon–Chai assertion |\r\n|--------------------------|-------------------------------------------------------------------|\r\n| called | spy.should.have.been.called |\r\n| callCount | spy.should.have.callCount(n) |\r\n| calledOnce | spy.should.have.been.calledOnce |\r\n| calledTwice | spy.should.have.been.calledTwice |\r\n| calledThrice | spy.should.have.been.calledThrice |\r\n| calledBefore | spy1.should.have.been.calledBefore(spy2) |\r\n| calledAfter | spy1.should.have.been.calledAfter(spy2) |\r\n| calledImmediatelyBefore | spy.should.have.been.calledImmediatelyBefore(spy2) |\r\n| calledImmediatelyAfter | spy.should.have.been.calledImmediatelyAfter(spy2) |\r\n| calledWithNew | spy.should.have.been.calledWithNew |\r\n| alwaysCalledWithNew | spy.should.always.have.been.calledWithNew |\r\n| calledOn | spy.should.have.been.calledOn(context) |\r\n| alwaysCalledOn | spy.should.always.have.been.calledOn(context) |\r\n| calledWith | spy.should.have.been.calledWith(...args) |\r\n| alwaysCalledWith | spy.should.always.have.been.calledWith(...args) |\r\n| calledOnceWith | spy.should.always.have.been.calledOnceWith(...args) |\r\n| calledWithExactly | spy.should.have.been.calledWithExactly(...args) |\r\n| alwaysCalledWithExactly | spy.should.always.have.been.calledWithExactly(...args) |\r\n| calledOnceWithExactly | spy.should.always.have.been.calledOnceWithExactly(...args) |\r\n| calledWithMatch | spy.should.have.been.calledWithMatch(...args) |\r\n| alwaysCalledWithMatch | spy.should.always.have.been.calledWithMatch(...args) |\r\n| returned | spy.should.have.returned(returnVal) |\r\n| alwaysReturned | spy.should.have.always.returned(returnVal) |\r\n| threw | spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing) |\r\n| alwaysThrew | spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing) |\r\n\r\nFor more information on the behavior of each assertion, see\r\n[the documentation for the corresponding spy methods][spymethods]. These of course work on not only spies, but\r\nindividual spy calls, stubs, and mocks as well.\r\n\r\nNote that you can negate any assertion with Chai's `.not`. E. g. for `notCalled` use `spy.should.have.not.been.called`.\r\n\r\nFor `assert` interface there is no need for this library. You can install [Sinon.JS assertions][sinonassertions] right into Chai's `assert` object with `expose`:\r\n\r\n```javascript\r\nvar chai = require(\"chai\");\r\nvar sinon = require(\"sinon\");\r\n\r\nsinon.assert.expose(chai.assert, { prefix: \"\" });\r\n```\r\n\r\n## Examples\r\n\r\nUsing Chai's `should`:\r\n\r\n```javascript\r\n\"use strict\";\r\nvar chai = require(\"chai\");\r\nvar sinon = require(\"sinon\");\r\nvar sinonChai = require(\"sinon-chai\");\r\nchai.should();\r\nchai.use(sinonChai);\r\n\r\nfunction hello(name, cb) {\r\n cb(\"hello \" + name);\r\n}\r\n\r\ndescribe(\"hello\", function () {\r\n it(\"should call callback with correct greeting\", function () {\r\n var cb = sinon.spy();\r\n\r\n hello(\"foo\", cb);\r\n\r\n cb.should.have.been.calledWith(\"hello foo\");\r\n });\r\n});\r\n```\r\n\r\nUsing Chai's `expect`:\r\n\r\n```javascript\r\n\"use strict\";\r\nvar chai = require(\"chai\");\r\nvar sinon = require(\"sinon\");\r\nvar sinonChai = require(\"sinon-chai\");\r\nvar expect = chai.expect;\r\nchai.use(sinonChai);\r\n\r\nfunction hello(name, cb) {\r\n cb(\"hello \" + name);\r\n}\r\n\r\ndescribe(\"hello\", function () {\r\n it(\"should call callback with correct greeting\", function () {\r\n var cb = sinon.spy();\r\n\r\n hello(\"foo\", cb);\r\n\r\n expect(cb).to.have.been.calledWith(\"hello foo\");\r\n });\r\n});\r\n```\r\n\r\n## Installation and Usage\r\n\r\n### Node\r\n\r\nDo an `npm install --save-dev sinon-chai` to get up and running. Then:\r\n\r\n```javascript\r\nvar chai = require(\"chai\");\r\nvar sinonChai = require(\"sinon-chai\");\r\n\r\nchai.use(sinonChai);\r\n```\r\n\r\nYou can of course put this code in a common test fixture file; for an example using [Mocha][], see\r\n[the Sinon–Chai tests themselves][fixturedemo].\r\n\r\n### AMD\r\n\r\nSinon–Chai supports being used as an [AMD][] module, registering itself anonymously (just like Chai). So, assuming you\r\nhave configured your loader to map the Chai and Sinon–Chai files to the respective module IDs `\"chai\"` and\r\n`\"sinon-chai\"`, you can use them as follows:\r\n\r\n```javascript\r\ndefine(function (require, exports, module) {\r\n var chai = require(\"chai\");\r\n var sinonChai = require(\"sinon-chai\");\r\n\r\n chai.use(sinonChai);\r\n});\r\n```\r\n\r\n### `\r\n\r\n\r\n```\r\n\r\n### Ruby on Rails\r\n\r\nThanks to [Cymen Vig][], there's now [a Ruby gem][] of Sinon–Chai that integrates it with the Rails asset pipeline!\r\n\r\n\r\n[Sinon.JS]: http://sinonjs.org/\r\n[Chai]: http://chaijs.com/\r\n[spymethods]: http://sinonjs.org/docs/#spies-api\r\n[sinonassertions]: http://sinonjs.org/docs/#assertions\r\n[Mocha]: https://mochajs.org/\r\n[fixturedemo]: https://github.com/domenic/sinon-chai/tree/master/test/\r\n[AMD]: https://github.com/amdjs/amdjs-api/wiki/AMD\r\n[Cymen Vig]: https://github.com/cymen\r\n[a Ruby gem]: https://github.com/cymen/sinon-chai-rails\r\n"}