Skip to content

Commit b1dfe08

Browse files
committed
Update docs/changelog.md and set new release id in docs/_config.yml
1 parent 32b2d77 commit b1dfe08

47 files changed

Lines changed: 19838 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: >-
55
url: 'https://sinonjs.org'
66
github_username: sinonjs
77
sinon:
8-
current_release: v9.2.2
8+
current_release: v9.2.3
99
markdown: kramdown
1010
kramdown:
1111
input: GFM

docs/_releases/latest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: page
33
title: API documentation - Sinon.JS
44
skip_ad: true
5-
release_id: v9.2.2
5+
release_id: v9.2.3
66
---
77

88
# {{page.title}} - `{{page.release_id}}`

docs/_releases/latest/fake-timers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ As above, but allows further configuration options, some of which are:
6161

6262
- `config.now` - *Number/Date* - installs lolex with the specified unix epoch (default: 0)
6363
- `config.toFake` - *String[ ]* - an array with explicit function names to fake. By default lolex will automatically fake all methods *except* `process.nextTick`. You could, however, still fake `nextTick` by providing it explicitly
64-
- `config.shouldAdvanceTime` - *Boolean* - tells lolex to increment mocked time automatically based on the real system time shift (default: false)
64+
- `config.shouldAdvanceTime` - *Boolean* - tells lolex to increment mocked time automatically based on the real system time shift (default: false). When used in conjunction with `config.toFake`, it will only work if `'setInterval'` is included in `config.toFake`.
6565

6666
Please refer to the `lolex.install` [documentation](https://github.com/sinonjs/lolex#var-clock--lolexinstallconfig) for the full set of features available and more elaborate explanations.
6767

docs/_releases/v9.2.3.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
layout: page
3+
title: API documentation - Sinon.JS
4+
skip_ad: true
5+
release_id: v9.2.3
6+
---
7+
8+
# {{page.title}} - `{{page.release_id}}`
9+
10+
This page contains the entire Sinon.JS API documentation along with brief introductions to the concepts Sinon implements.
11+
12+
* [General setup](./general-setup)
13+
* [Fakes](./fakes)
14+
* [Spies](./spies)
15+
* [Stubs](./stubs)
16+
* [Mocks](./mocks)
17+
* [Spy calls](./spy-call)
18+
* [Fake timers](./fake-timers)
19+
* [Fake <code>XHR</code> and server](./fake-xhr-and-server)
20+
* [JSON-P](./json-p)
21+
* [Assertions](./assertions)
22+
* [Matchers](./matchers)
23+
* [Sandboxes](./sandbox)
24+
* [Utils](./utils)
25+
26+
{% include docs/migration-guides.md %}
27+
28+
### Compatibility
29+
30+
### ES5.1
31+
32+
Sinon `{{page.release_id}}` is written as [ES5.1][ES5] and requires no transpiler or polyfills to run in the runtimes listed below.
33+
34+
### Supported runtimes
35+
36+
`{{page.release_id}}` has been verified in these runtimes:
37+
38+
* Firefox 45
39+
* Chrome 48
40+
* Internet Explorer 11
41+
* Edge 14
42+
* Safari 9
43+
* [Node.js LTS versions](https://github.com/nodejs/Release)
44+
45+
There should not be any issues with using Sinon `{{page.release_id}}` in newer versions of the same runtimes.
46+
47+
If you need to support very old runtimes that have incomplete support for [ES5.1][ES5] you might get away with using loading [`es5-shim`][es5-shim] in your test environment.
48+
49+
{% include docs/contribute.md %}
50+
51+
[ES5]: http://www.ecma-international.org/ecma-262/5.1/
52+
[es5-shim]: https://github.com/es-shims/es5-shim
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
---
2+
layout: page
3+
title: Assertions - Sinon.JS
4+
breadcrumb: assertions
5+
---
6+
7+
Sinon.JS ships with a set of assertions that mirror most behavior verification methods and properties on spies and stubs. The advantage of using the assertions is that failed expectations on stubs and spies can be expressed directly as assertion failures with detailed and helpful error messages.
8+
9+
To make sure assertions integrate nicely with your test framework, you should customize either `sinon.assert.fail` or `sinon.assert.failException` and look into `sinon.assert.expose` and `sinon.assert.pass`.
10+
11+
The assertions can be used with either spies or stubs.
12+
13+
```javascript
14+
"test should call subscribers with message as first argument" : function () {
15+
var message = "an example message";
16+
var spy = sinon.spy();
17+
18+
PubSub.subscribe(message, spy);
19+
PubSub.publishSync(message, "some payload");
20+
21+
sinon.assert.calledOnce(spy);
22+
sinon.assert.calledWith(spy, message);
23+
}
24+
```
25+
26+
## Assertions API
27+
28+
#### `sinon.assert.fail(message)`
29+
30+
Every assertion fails by calling this method.
31+
32+
By default it throws an error of type `sinon.assert.failException`.
33+
34+
If the test framework looks for assertion errors by checking for a specific exception, you can override the kind of exception thrown. If that does not fit with your testing framework of choice, override the `fail` method to do the right thing.
35+
36+
37+
#### `sinon.assert.failException;`
38+
39+
Defaults to `AssertError`.
40+
41+
42+
#### `sinon.assert.pass(assertion);`
43+
44+
Called every time `assertion` passes.
45+
46+
Default implementation does nothing.
47+
48+
49+
#### `sinon.assert.notCalled(spy);`
50+
51+
Passes if `spy` was never called
52+
53+
#### `sinon.assert.called(spy);`
54+
55+
Passes if `spy` was called at least once.
56+
57+
58+
#### `sinon.assert.calledOnce(spy);`
59+
60+
Passes if `spy` was called once and only once.
61+
62+
63+
#### `sinon.assert.calledTwice(spy);`
64+
65+
Passes if `spy` was called exactly twice.
66+
67+
68+
#### `sinon.assert.calledThrice(spy)`
69+
70+
Passes if `spy` was called exactly three times.
71+
72+
73+
#### `sinon.assert.callCount(spy, num)`
74+
Passes if `spy` was called exactly `num` times.
75+
76+
77+
#### `sinon.assert.callOrder(spy1, spy2, ...)`
78+
Passes if provided spies were called in the specified order.
79+
80+
81+
#### `sinon.assert.calledOn(spyOrSpyCall, obj)`
82+
83+
Passes if `spy` was ever called with `obj` as its `this` value.
84+
85+
It's possible to assert on a dedicated spy call: `sinon.assert.calledOn(spy.firstCall, arg1, arg2, ...);`.
86+
87+
88+
#### `sinon.assert.alwaysCalledOn(spy, obj)`
89+
90+
Passes if `spy` was always called with `obj` as its `this` value.
91+
92+
93+
#### `sinon.assert.calledWith(spyOrSpyCall, arg1, arg2, ...);`
94+
95+
Passes if `spy` was called with the provided arguments.
96+
97+
It's possible to assert on a dedicated spy call: `sinon.assert.calledWith(spy.firstCall, arg1, arg2, ...);`.
98+
99+
100+
#### `sinon.assert.alwaysCalledWith(spy, arg1, arg2, ...);`
101+
102+
Passes if `spy` was always called with the provided arguments.
103+
104+
105+
#### `sinon.assert.neverCalledWith(spy, arg1, arg2, ...);`
106+
107+
Passes if `spy` was never called with the provided arguments.
108+
109+
110+
#### `sinon.assert.calledWithExactly(spyOrSpyCall, arg1, arg2, ...);`
111+
112+
Passes if `spy` was called with the provided arguments and no others.
113+
114+
It's possible to assert on a dedicated spy call: `sinon.assert.calledWithExactly(spy.getCall(1), arg1, arg2, ...);`.
115+
116+
117+
#### `sinon.assert.calledOnceWithExactly(spyOrSpyCall, arg1, arg2, ...);`
118+
119+
Passes if `spy` was called once and only once with the provided arguments and no others.
120+
121+
It's possible to assert on a dedicated spy call: `sinon.assert.calledOnceWithExactly(spy.getCall(1), arg1, arg2, ...);`.
122+
123+
124+
#### `sinon.assert.alwaysCalledWithExactly(spy, arg1, arg2, ...);`
125+
126+
Passes if `spy` was always called with the provided arguments and no others.
127+
128+
129+
#### `sinon.assert.calledWithMatch(spyOrSpyCall, arg1, arg2, ...)`
130+
131+
Passes if `spy` was called with matching arguments.
132+
133+
This behaves the same way as `sinon.assert.calledWith(spy, sinon.match(arg1), sinon.match(arg2), ...)`.
134+
135+
It's possible to assert on a dedicated spy call: `sinon.assert.calledWithMatch(spy.secondCall, arg1, arg2, ...);`.
136+
137+
138+
#### `sinon.assert.alwaysCalledWithMatch(spy, arg1, arg2, ...)`
139+
140+
Passes if `spy` was always called with matching arguments.
141+
142+
This behaves the same way as `sinon.assert.alwaysCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...)`.
143+
144+
145+
#### `sinon.assert.calledWithNew(spyOrSpyCall)`
146+
147+
Passes if `spy` was called with the `new` operator.
148+
149+
It's possible to assert on a dedicated spy call: `sinon.assert.calledWithNew(spy.secondCall, arg1, arg2, ...);`.
150+
151+
152+
#### `sinon.assert.neverCalledWithMatch(spy, arg1, arg2, ...)`
153+
154+
Passes if `spy` was never called with matching arguments.
155+
156+
This behaves the same way as `sinon.assert.neverCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...)`.
157+
158+
159+
#### `sinon.assert.threw(spyOrSpyCall, exception);`
160+
161+
Passes if `spy` threw the given exception.
162+
163+
The exception can be a `String` denoting its type, or an actual object.
164+
165+
If only one argument is provided, the assertion passes if `spy` ever threw any exception.
166+
167+
It's possible to assert on a dedicated spy call: `sinon.assert.threw(spy.thirdCall, exception);`.
168+
169+
170+
#### `sinon.assert.alwaysThrew(spy, exception);`
171+
172+
Like above, only required for all calls to the spy.
173+
174+
#### `sinon.assert.match(actual, expectation);`
175+
176+
Uses [`sinon.match`](../matchers) to test if the arguments can be considered a match.
177+
178+
```javascript
179+
var sinon = require('sinon');
180+
181+
describe('example', function(){
182+
it('should match on `x` property, and ignore `y` property', function() {
183+
var expected = {x: 1},
184+
actual = {x: 1, y: 2};
185+
186+
sinon.assert.match(actual, expected);
187+
});
188+
});
189+
```
190+
191+
#### `sinon.assert.expose(object, options);`
192+
193+
Exposes assertions into another object, to better integrate with the test framework. For instance, JsTestDriver uses global assertions, and to make Sinon.JS assertions appear alongside them, you can do.
194+
195+
```javascript
196+
sinon.assert.expose(this);
197+
```
198+
199+
This will give you `assertCalled(spy)`,`assertCallOrder(spy1, spy2, ...)` and so on.
200+
201+
The method accepts an optional options object with two options.
202+
203+
<dl>
204+
<dt>prefix</dt>
205+
<dd>is a prefix to give assertions. By default it is "assert", so <code>sinon.assert.called</code> becomes <code>target.assertCalled</code>. By passing a blank string, the exposed method will be <code>target.called</code>.</dd>
206+
207+
<dt>includeFail</dt>
208+
<dd><code>true</code> by default, copies over the <code>fail</code> and <code>failException</code> properties</dd>
209+
</dl>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
env:
2+
es6: true
3+
4+
parserOptions:
5+
ecmaVersion: 2017
6+
7+
extends:
8+
- ../../../../test/.eslintrc.yml
9+
10+
plugins:
11+
- local-rules
12+
13+
rules:
14+
local-rules/no-underscore-dangle: off
15+
no-underscore-dangle: off
16+
no-console: off
17+
no-empty-function: off
18+
mocha/no-setup-in-describe: off
19+
no-var: error
20+
prefer-const: error
21+
strict: off # cannot use strict mode in RunKit due to it using `with` tricks
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock.json
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "examples",
3+
"version": "1.0.0",
4+
"description": "Simulate running the Sinon runnable examples in RunKit",
5+
"scripts": {
6+
"test": "./run-test.sh"
7+
},
8+
"license": "ISC",
9+
"// dependencies": "We use 'latest' for the versions, as that is what RunKit will use",
10+
"dependencies": {
11+
"@fatso83/mini-mocha": "latest",
12+
"@sinonjs/referee": "latest",
13+
"bluebird": "latest",
14+
"jquery": "latest",
15+
"jsdom": "latest",
16+
"pubsub-js": "latest",
17+
"sinon": "latest"
18+
},
19+
"devDependencies": {
20+
"eslint": "^6.8.0"
21+
}
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Link 'sinon' to local development dir
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
cd "$SCRIPT_DIR/.."
6+
npm link
7+
8+
# Install examples project and link to local sinon folder
9+
cd "$SCRIPT_DIR"
10+
npm install --ignore-scripts
11+
npm link sinon
12+
13+
# Lint
14+
$(npm bin)/eslint .
15+
16+
# Make sure all examples are still runnable
17+
set -e
18+
for f in *.test.js; do
19+
node $f
20+
done
21+
set +e
22+
23+
# clean up to avoid circular links confusing watchers
24+
npm unlink sinon
25+
git checkout -- package.json
26+
npm install --ignore-scripts
27+
cd "$SCRIPT_DIR/.."
28+
npm unlink
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const PubSub = require("pubsub-js");
4+
const referee = require("@sinonjs/referee");
5+
const assertTrue = referee.assert;
6+
7+
describe("PubSub", function() {
8+
it("should call subscribers on publish", function() {
9+
const callback = sinon.spy();
10+
11+
PubSub.subscribe("message", callback);
12+
PubSub.publishSync("message");
13+
14+
assertTrue(callback.called);
15+
});
16+
});

0 commit comments

Comments
 (0)