@sequencemedia/sinon-chai 0.0.5 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,183 +1,7 @@
1
- # Sinon.JS Assertions for Chai
1
+ # @sequencemedia/sinon-chai
2
2
 
3
- **Sinon–Chai** provides a set of custom assertions for using the [Sinon.JS][] spy, stub, and mocking framework with the
4
- [Chai][] assertion library. You get all the benefits of Chai with all the powerful tools of Sinon.JS.
3
+ This project is a fork of *sinon-chai* `v3.7.0` updated with latest dependencies
5
4
 
6
- Instead of using Sinon.JS's assertions:
5
+ ## Documentation
7
6
 
8
- ```javascript
9
- sinon.assert.calledWith(mySpy, "foo");
10
- ```
11
-
12
- or awkwardly trying to use Chai's `should` or `expect` interfaces on spy properties:
13
-
14
- ```javascript
15
- mySpy.calledWith("foo").should.be.ok;
16
- expect(mySpy.calledWith("foo")).to.be.ok;
17
- ```
18
-
19
- you can say
20
-
21
- ```javascript
22
- mySpy.should.have.been.calledWith("foo");
23
- expect(mySpy).to.have.been.calledWith("foo");
24
- ```
25
-
26
- ## Assertions
27
-
28
- All of your favorite Sinon.JS assertions made their way into Sinon–Chai. We show the `should` syntax here; the `expect`
29
- equivalent is also available.
30
-
31
- | Sinon.JS property/method | Sinon–Chai assertion |
32
- |--------------------------|-------------------------------------------------------------------|
33
- | called | spy.should.have.been.called |
34
- | callCount | spy.should.have.callCount(n) |
35
- | calledOnce | spy.should.have.been.calledOnce |
36
- | calledTwice | spy.should.have.been.calledTwice |
37
- | calledThrice | spy.should.have.been.calledThrice |
38
- | calledBefore | spy1.should.have.been.calledBefore(spy2) |
39
- | calledAfter | spy1.should.have.been.calledAfter(spy2) |
40
- | calledImmediatelyBefore | spy.should.have.been.calledImmediatelyBefore(spy2) |
41
- | calledImmediatelyAfter | spy.should.have.been.calledImmediatelyAfter(spy2) |
42
- | calledWithNew | spy.should.have.been.calledWithNew |
43
- | alwaysCalledWithNew | spy.should.always.have.been.calledWithNew |
44
- | calledOn | spy.should.have.been.calledOn(context) |
45
- | alwaysCalledOn | spy.should.always.have.been.calledOn(context) |
46
- | calledWith | spy.should.have.been.calledWith(...args) |
47
- | alwaysCalledWith | spy.should.always.have.been.calledWith(...args) |
48
- | calledOnceWith | spy.should.always.have.been.calledOnceWith(...args) |
49
- | calledWithExactly | spy.should.have.been.calledWithExactly(...args) |
50
- | alwaysCalledWithExactly | spy.should.always.have.been.calledWithExactly(...args) |
51
- | calledOnceWithExactly | spy.should.always.have.been.calledOnceWithExactly(...args) |
52
- | calledWithMatch | spy.should.have.been.calledWithMatch(...args) |
53
- | alwaysCalledWithMatch | spy.should.always.have.been.calledWithMatch(...args) |
54
- | returned | spy.should.have.returned(returnVal) |
55
- | alwaysReturned | spy.should.have.always.returned(returnVal) |
56
- | threw | spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing) |
57
- | alwaysThrew | spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing) |
58
-
59
- For more information on the behavior of each assertion, see
60
- [the documentation for the corresponding spy methods][spymethods]. These of course work on not only spies, but
61
- individual spy calls, stubs, and mocks as well.
62
-
63
- Note 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`.
64
-
65
- For 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.
66
-
67
- For `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`:
68
-
69
- ```javascript
70
- var chai = require("chai");
71
- var sinon = require("sinon");
72
-
73
- sinon.assert.expose(chai.assert, { prefix: "" });
74
- ```
75
-
76
- ## Examples
77
-
78
- Using Chai's `should`:
79
-
80
- ```javascript
81
- "use strict";
82
- var chai = require("chai");
83
- var sinon = require("sinon");
84
- var sinonChai = require("sinon-chai");
85
- chai.should();
86
- chai.use(sinonChai);
87
-
88
- function hello(name, cb) {
89
- cb("hello " + name);
90
- }
91
-
92
- describe("hello", function () {
93
- it("should call callback with correct greeting", function () {
94
- var cb = sinon.spy();
95
-
96
- hello("foo", cb);
97
-
98
- cb.should.have.been.calledWith("hello foo");
99
- });
100
- });
101
- ```
102
-
103
- Using Chai's `expect`:
104
-
105
- ```javascript
106
- "use strict";
107
- var chai = require("chai");
108
- var sinon = require("sinon");
109
- var sinonChai = require("sinon-chai");
110
- var expect = chai.expect;
111
- chai.use(sinonChai);
112
-
113
- function hello(name, cb) {
114
- cb("hello " + name);
115
- }
116
-
117
- describe("hello", function () {
118
- it("should call callback with correct greeting", function () {
119
- var cb = sinon.spy();
120
-
121
- hello("foo", cb);
122
-
123
- expect(cb).to.have.been.calledWith("hello foo");
124
- });
125
- });
126
- ```
127
-
128
- ## Installation and Usage
129
-
130
- ### Node
131
-
132
- Do an `npm install --save-dev sinon-chai` to get up and running. Then:
133
-
134
- ```javascript
135
- var chai = require("chai");
136
- var sinonChai = require("sinon-chai");
137
-
138
- chai.use(sinonChai);
139
- ```
140
-
141
- You can of course put this code in a common test fixture file; for an example using [Mocha][], see
142
- [the Sinon–Chai tests themselves][fixturedemo].
143
-
144
- ### AMD
145
-
146
- Sinon–Chai supports being used as an [AMD][] module, registering itself anonymously (just like Chai). So, assuming you
147
- have configured your loader to map the Chai and Sinon–Chai files to the respective module IDs `"chai"` and
148
- `"sinon-chai"`, you can use them as follows:
149
-
150
- ```javascript
151
- define(function (require, exports, module) {
152
- var chai = require("chai");
153
- var sinonChai = require("sinon-chai");
154
-
155
- chai.use(sinonChai);
156
- });
157
- ```
158
-
159
- ### `<script>` tag
160
-
161
- If you include Sinon–Chai directly with a `<script>` tag, after the one for Chai itself, then it will automatically plug
162
- in to Chai and be ready for use. Note that you'll want to get the latest browser build of Sinon.JS as well:
163
-
164
- ```html
165
- <script src="chai.js"></script>
166
- <script src="sinon-chai.js"></script>
167
- <script src="sinon.js"></script>
168
- ```
169
-
170
- ### Ruby on Rails
171
-
172
- Thanks to [Cymen Vig][], there's now [a Ruby gem][] of Sinon–Chai that integrates it with the Rails asset pipeline!
173
-
174
-
175
- [Sinon.JS]: http://sinonjs.org/
176
- [Chai]: http://chaijs.com/
177
- [spymethods]: http://sinonjs.org/docs/#spies-api
178
- [sinonassertions]: http://sinonjs.org/docs/#assertions
179
- [Mocha]: https://mochajs.org/
180
- [fixturedemo]: https://github.com/domenic/sinon-chai/tree/master/test/
181
- [AMD]: https://github.com/amdjs/amdjs-api/wiki/AMD
182
- [Cymen Vig]: https://github.com/cymen
183
- [a Ruby gem]: https://github.com/cymen/sinon-chai-rails
7
+ Refer to [documentation at the *sinon-chai* repository](https://github.com/domenic/sinon-chai)
@@ -0,0 +1,53 @@
1
+ import globals from 'globals'
2
+ import standard from '@sequencemedia/eslint-config-standard'
3
+
4
+ function merge (alpha) {
5
+ return (
6
+ standard
7
+ .map((omega) => ({
8
+ ...omega,
9
+ ...alpha
10
+ }))
11
+ )
12
+ }
13
+
14
+ export default (
15
+ merge({
16
+ ignores: [
17
+ 'coverage/*',
18
+ 'test/*'
19
+ ],
20
+ languageOptions: {
21
+ globals: {
22
+ define: 'readonly',
23
+ ...globals.node
24
+ }
25
+ }
26
+ })
27
+ .concat(
28
+ merge({
29
+ files: [
30
+ 'test/*'
31
+ ],
32
+ languageOptions: {
33
+ globals: {
34
+ ...globals.mocha
35
+ }
36
+ }
37
+ }).concat({
38
+ files: [
39
+ 'test/*'
40
+ ],
41
+ languageOptions: {
42
+ globals: {
43
+ ...globals.mocha
44
+ }
45
+ },
46
+ rules: {
47
+ 'no-unused-expressions': 'off',
48
+ 'no-new': 'off',
49
+ 'new-cap': 'off'
50
+ }
51
+ })
52
+ )
53
+ )
@@ -1,5 +1,4 @@
1
1
  'use strict';
2
- /* eslint-disable no-invalid-this */
3
2
 
4
3
  (function (sinonChai) {
5
4
  // Module systems magic dance.
@@ -10,7 +9,7 @@
10
9
  module.exports = sinonChai
11
10
  } else if (typeof define === 'function' && define.amd) {
12
11
  // AMD
13
- define(function () {
12
+ define(() => {
14
13
  return sinonChai
15
14
  })
16
15
  } else {
@@ -22,9 +21,11 @@
22
21
  const slice = Array.prototype.slice
23
22
 
24
23
  function isSpy (putativeSpy) {
25
- return typeof putativeSpy === 'function' &&
26
- typeof putativeSpy.getCall === 'function' &&
27
- typeof putativeSpy.calledWithExactly === 'function'
24
+ return (
25
+ typeof putativeSpy === 'function' &&
26
+ typeof putativeSpy.getCall === 'function' &&
27
+ typeof putativeSpy.calledWithExactly === 'function'
28
+ )
28
29
  }
29
30
 
30
31
  function timesInWords (count) {
@@ -66,17 +67,17 @@
66
67
  }
67
68
 
68
69
  return {
69
- affirmative: function () {
70
+ affirmative () {
70
71
  return printfArray([`expected %n to ${verbPhrase}${action}${nonNegatedSuffix}`].concat(args))
71
72
  },
72
- negative: function () {
73
+ negative () {
73
74
  return printfArray([`expected %n to not ${verbPhrase}${action}`].concat(args))
74
75
  }
75
76
  }
76
77
  }
77
78
 
78
79
  function sinonProperty (name, action, nonNegatedSuffix) {
79
- utils.addProperty(chai.Assertion.prototype, name, function () {
80
+ utils.addProperty(chai.Assertion.prototype, name, function handler () {
80
81
  assertCanWorkWith(this)
81
82
 
82
83
  const messages = getMessages(this._obj, action, nonNegatedSuffix, false)
@@ -85,7 +86,7 @@
85
86
  }
86
87
 
87
88
  function sinonPropertyAsBooleanMethod (name, action, nonNegatedSuffix) {
88
- utils.addMethod(chai.Assertion.prototype, name, function (arg) {
89
+ utils.addMethod(chai.Assertion.prototype, name, function handler (arg) {
89
90
  assertCanWorkWith(this)
90
91
 
91
92
  const messages = getMessages(this._obj, action, nonNegatedSuffix, false, [timesInWords(arg)])
@@ -94,16 +95,16 @@
94
95
  }
95
96
 
96
97
  function createSinonMethodHandler (sinonName, action, nonNegatedSuffix) {
97
- return function () {
98
+ return function sinonMethodHandler (...args) {
98
99
  assertCanWorkWith(this)
99
100
 
100
101
  const alwaysSinonMethod = 'always' + sinonName[0].toUpperCase() + sinonName.substring(1)
101
102
  const shouldBeAlways = utils.flag(this, 'always') && typeof this._obj[alwaysSinonMethod] === 'function'
102
103
  const sinonMethodName = shouldBeAlways ? alwaysSinonMethod : sinonName
103
104
 
104
- const messages = getMessages(this._obj, action, nonNegatedSuffix, shouldBeAlways, slice.call(arguments))
105
+ const messages = getMessages(this._obj, action, nonNegatedSuffix, shouldBeAlways, slice.call(args))
105
106
  this.assert(
106
- this._obj[sinonMethodName].apply(this._obj, arguments),
107
+ this._obj[sinonMethodName].apply(this._obj, args),
107
108
  messages.affirmative,
108
109
  messages.negative
109
110
  )
@@ -124,7 +125,7 @@
124
125
  exceptionalSinonMethod(name, name, action, nonNegatedSuffix)
125
126
  }
126
127
 
127
- utils.addProperty(chai.Assertion.prototype, 'always', function () {
128
+ utils.addProperty(chai.Assertion.prototype, 'always', function always () {
128
129
  utils.flag(this, 'always', true)
129
130
  })
130
131
 
@@ -0,0 +1,2 @@
1
+ export = sinonChai;
2
+ //# sourceMappingURL=sinon-chai.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sinon-chai.d.cts","sourceRoot":"","sources":["sinon-chai.cjs"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sequencemedia/sinon-chai",
3
- "version": "0.0.5",
4
- "description": "Extends Chai with assertions for the Sinon.JS mocking framework.",
3
+ "version": "0.0.8",
4
+ "description": "Extends Chai with assertions for Sinon",
5
5
  "keywords": [
6
6
  "chai",
7
7
  "chai-plugin",
@@ -16,33 +16,47 @@
16
16
  ],
17
17
  "main": "./lib/sinon-chai.cjs",
18
18
  "type": "module",
19
+ "types": "./lib/sinon-chai.d.cts",
19
20
  "author": {
20
21
  "name": "Jonathan Perry for Sequence Media Limited",
21
22
  "email": "sequencemedia@sequencemedia.net",
22
- "url": "http://sequencemedia.net"
23
+ "url": "https://sequencemedia.net"
23
24
  },
24
25
  "contributors": [
25
26
  "Domenic Denicola <d@domenic.me> (https://domenic.me/)",
26
27
  "Simon de Lang <simondelang@gmail.com>"
27
28
  ],
28
29
  "license": "(BSD-2-Clause OR WTFPL)",
29
- "repository": "sequencemedia/sinon-chai",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/sequencemedia/sinon-chai.git"
33
+ },
30
34
  "scripts": {
31
- "test": "mocha",
32
- "lint": "eslint . --ext .mjs,.cjs",
35
+ "coverage": "c8 --reporter=html mocha",
36
+ "lint": "eslint .",
33
37
  "lint:fix": "npm run lint -- --fix",
34
- "coverage": "c8 --reporter=html mocha"
38
+ "test": "mocha",
39
+ "types": "tsc",
40
+ "prepare": "husky"
35
41
  },
36
42
  "devDependencies": {
37
- "@babel/core": "^7.23.7",
38
- "@babel/eslint-parser": "^7.23.3",
39
- "@babel/preset-env": "^7.23.7",
40
- "core-js": "^3.35.0",
41
- "eslint": "^8.56.0",
42
- "eslint-config-standard": "^17.1.0",
43
- "c8": "^9.0.0",
44
- "chai": "^5.0.0",
45
- "mocha": "^10.2.0",
46
- "sinon": "^17.0.1"
43
+ "@babel/core": "^7.24.7",
44
+ "@babel/eslint-parser": "^7.24.7",
45
+ "@babel/preset-env": "^7.24.7",
46
+ "@sequencemedia/eslint-config-standard": "^0.0.8",
47
+ "@sequencemedia/hooks": "^1.0.497",
48
+ "c8": "^10.1.2",
49
+ "chai": "^5.1.1",
50
+ "core-js": "^3.37.1",
51
+ "eslint": "^9.6.0",
52
+ "husky": "^9.0.11",
53
+ "mocha": "^10.6.0",
54
+ "sinon": "^18.0.0",
55
+ "typescript": "^5.5.3"
56
+ },
57
+ "peerDependencies": {
58
+ "chai": ">=5.0.0",
59
+ "mocha": ">=10.2.0",
60
+ "sinon": ">=17.0.0"
47
61
  }
48
62
  }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
6
+ "declarationMap": true
7
+ },
8
+ "include": [
9
+ "lib"
10
+ ]
11
+ }
package/.mocharc.mjs DELETED
@@ -1,3 +0,0 @@
1
- export default {
2
- require: ["./test/common.mjs"]
3
- }