@sequencemedia/sinon-chai 0.0.6 → 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.
@@ -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) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sequencemedia/sinon-chai",
3
- "version": "0.0.6",
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",
@@ -20,33 +20,39 @@
20
20
  "author": {
21
21
  "name": "Jonathan Perry for Sequence Media Limited",
22
22
  "email": "sequencemedia@sequencemedia.net",
23
- "url": "http://sequencemedia.net"
23
+ "url": "https://sequencemedia.net"
24
24
  },
25
25
  "contributors": [
26
26
  "Domenic Denicola <d@domenic.me> (https://domenic.me/)",
27
27
  "Simon de Lang <simondelang@gmail.com>"
28
28
  ],
29
29
  "license": "(BSD-2-Clause OR WTFPL)",
30
- "repository": "sequencemedia/sinon-chai",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/sequencemedia/sinon-chai.git"
33
+ },
31
34
  "scripts": {
32
- "types": "tsc",
33
- "test": "mocha",
34
- "lint": "eslint . --ext .mjs,.cjs",
35
+ "coverage": "c8 --reporter=html mocha",
36
+ "lint": "eslint .",
35
37
  "lint:fix": "npm run lint -- --fix",
36
- "coverage": "c8 --reporter=html mocha"
38
+ "test": "mocha",
39
+ "types": "tsc",
40
+ "prepare": "husky"
37
41
  },
38
42
  "devDependencies": {
39
- "@babel/core": "^7.23.7",
40
- "@babel/eslint-parser": "^7.23.3",
41
- "@babel/preset-env": "^7.23.7",
42
- "c8": "^9.0.0",
43
- "chai": "^5.0.0",
44
- "core-js": "^3.35.0",
45
- "eslint": "^8.56.0",
46
- "eslint-config-standard": "^17.1.0",
47
- "mocha": "^10.2.0",
48
- "sinon": "^17.0.1",
49
- "typescript": "^5.3.3"
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"
50
56
  },
51
57
  "peerDependencies": {
52
58
  "chai": ">=5.0.0",
package/tsconfig.json CHANGED
@@ -1,17 +1,11 @@
1
1
  {
2
- // Change this to match your project
3
- "include": ["lib"],
4
2
  "compilerOptions": {
5
- // Tells TypeScript to read JS files, as
6
- // normally they are ignored as source files
7
3
  "allowJs": true,
8
- // Generate d.ts files
9
4
  "declaration": true,
10
- // This compiler run should
11
- // only output d.ts files
12
5
  "emitDeclarationOnly": true,
13
- // go to js file when using IDE functions like
14
- // "Go to Definition" in VSCode
15
6
  "declarationMap": true
16
- }
7
+ },
8
+ "include": [
9
+ "lib"
10
+ ]
17
11
  }
package/.mocharc.mjs DELETED
@@ -1,3 +0,0 @@
1
- export default {
2
- require: ["./test/common.mjs"]
3
- }