Skip to content

Commit

Permalink
Update docs/changelog.md and set new release id in docs/_config.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed Mar 22, 2021
1 parent 2e8a1ce commit e3b3195
Show file tree
Hide file tree
Showing 82 changed files with 20,371 additions and 504 deletions.
2 changes: 1 addition & 1 deletion docs/_config.yml
Expand Up @@ -5,7 +5,7 @@ description: >-
url: 'https://sinonjs.org'
github_username: sinonjs
sinon:
current_release: v9.2.4
current_release: v10.0.0
markdown: kramdown
kramdown:
input: GFM
Expand Down
46 changes: 23 additions & 23 deletions docs/_releases/latest.md
Expand Up @@ -2,51 +2,51 @@
layout: page
title: API documentation - Sinon.JS
skip_ad: true
release_id: v9.2.4
release_id: v10.0.0
---

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

This page contains the entire Sinon.JS API documentation along with brief introductions to the concepts Sinon implements.

* [General setup](./general-setup)
* [Fakes](./fakes)
* [Spies](./spies)
* [Stubs](./stubs)
* [Mocks](./mocks)
* [Spy calls](./spy-call)
* [Fake timers](./fake-timers)
* [Fake <code>XHR</code> and server](./fake-xhr-and-server)
* [JSON-P](./json-p)
* [Assertions](./assertions)
* [Matchers](./matchers)
* [Sandboxes](./sandbox)
* [Utils](./utils)
- [General setup](./general-setup)
- [Fakes](./fakes)
- [Spies](./spies)
- [Stubs](./stubs)
- [Mocks](./mocks)
- [Spy calls](./spy-call)
- [Fake timers](./fake-timers)
- [Fake <code>XHR</code> and server](./fake-xhr-and-server)
- [JSON-P](./json-p)
- [Assertions](./assertions)
- [Matchers](./matchers)
- [Sandboxes](./sandbox)
- [Utils](./utils)

{% include docs/migration-guides.md %}

### Compatibility

### ES5.1

Sinon `{{page.release_id}}` is written as [ES5.1][ES5] and requires no transpiler or polyfills to run in the runtimes listed below.
Sinon `{{page.release_id}}` is written as [ES5.1][es5] and requires no transpiler or polyfills to run in the runtimes listed below.

### Supported runtimes

`{{page.release_id}}` has been verified in these runtimes:

* Firefox 45
* Chrome 48
* Internet Explorer 11
* Edge 14
* Safari 9
* [Node.js LTS versions](https://github.com/nodejs/Release)
- Firefox 45
- Chrome 48
- Internet Explorer 11
- Edge 14
- Safari 9
- [Node.js LTS versions](https://github.com/nodejs/Release)

There should not be any issues with using Sinon `{{page.release_id}}` in newer versions of the same runtimes.

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.
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.

{% include docs/contribute.md %}

[ES5]: http://www.ecma-international.org/ecma-262/5.1/
[es5]: http://www.ecma-international.org/ecma-262/5.1/
[es5-shim]: https://github.com/es-shims/es5-shim
39 changes: 10 additions & 29 deletions docs/_releases/latest/assertions.md
Expand Up @@ -33,19 +33,16 @@ By default it throws an error of type `sinon.assert.failException`.

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.


#### `sinon.assert.failException;`

Defaults to `AssertError`.


#### `sinon.assert.pass(assertion);`

Called every time `assertion` passes.

Default implementation does nothing.


#### `sinon.assert.notCalled(spy);`

Passes if `spy` was never called
Expand All @@ -54,78 +51,66 @@ Passes if `spy` was never called

Passes if `spy` was called at least once.


#### `sinon.assert.calledOnce(spy);`

Passes if `spy` was called once and only once.


#### `sinon.assert.calledTwice(spy);`

Passes if `spy` was called exactly twice.


#### `sinon.assert.calledThrice(spy)`

Passes if `spy` was called exactly three times.


#### `sinon.assert.callCount(spy, num)`
Passes if `spy` was called exactly `num` times.

Passes if `spy` was called exactly `num` times.

#### `sinon.assert.callOrder(spy1, spy2, ...)`
Passes if provided spies were called in the specified order.

Passes if provided spies were called in the specified order.

#### `sinon.assert.calledOn(spyOrSpyCall, obj)`

Passes if `spy` was ever called with `obj` as its `this` value.

It's possible to assert on a dedicated spy call: `sinon.assert.calledOn(spy.firstCall, arg1, arg2, ...);`.


#### `sinon.assert.alwaysCalledOn(spy, obj)`

Passes if `spy` was always called with `obj` as its `this` value.


#### `sinon.assert.calledWith(spyOrSpyCall, arg1, arg2, ...);`

Passes if `spy` was called with the provided arguments.

It's possible to assert on a dedicated spy call: `sinon.assert.calledWith(spy.firstCall, arg1, arg2, ...);`.


#### `sinon.assert.alwaysCalledWith(spy, arg1, arg2, ...);`

Passes if `spy` was always called with the provided arguments.


#### `sinon.assert.neverCalledWith(spy, arg1, arg2, ...);`

Passes if `spy` was never called with the provided arguments.


#### `sinon.assert.calledWithExactly(spyOrSpyCall, arg1, arg2, ...);`

Passes if `spy` was called with the provided arguments and no others.

It's possible to assert on a dedicated spy call: `sinon.assert.calledWithExactly(spy.getCall(1), arg1, arg2, ...);`.


#### `sinon.assert.calledOnceWithExactly(spyOrSpyCall, arg1, arg2, ...);`

Passes if `spy` was called once and only once with the provided arguments and no others.

It's possible to assert on a dedicated spy call: `sinon.assert.calledOnceWithExactly(spy.getCall(1), arg1, arg2, ...);`.


#### `sinon.assert.alwaysCalledWithExactly(spy, arg1, arg2, ...);`

Passes if `spy` was always called with the provided arguments and no others.


#### `sinon.assert.calledWithMatch(spyOrSpyCall, arg1, arg2, ...)`

Passes if `spy` was called with matching arguments.
Expand All @@ -134,28 +119,24 @@ This behaves the same way as `sinon.assert.calledWith(spy, sinon.match(arg1), si

It's possible to assert on a dedicated spy call: `sinon.assert.calledWithMatch(spy.secondCall, arg1, arg2, ...);`.


#### `sinon.assert.alwaysCalledWithMatch(spy, arg1, arg2, ...)`

Passes if `spy` was always called with matching arguments.

This behaves the same way as `sinon.assert.alwaysCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...)`.


#### `sinon.assert.calledWithNew(spyOrSpyCall)`

Passes if `spy` was called with the `new` operator.

It's possible to assert on a dedicated spy call: `sinon.assert.calledWithNew(spy.secondCall, arg1, arg2, ...);`.


#### `sinon.assert.neverCalledWithMatch(spy, arg1, arg2, ...)`

Passes if `spy` was never called with matching arguments.

This behaves the same way as `sinon.assert.neverCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...)`.


#### `sinon.assert.threw(spyOrSpyCall, exception);`

Passes if `spy` threw the given exception.
Expand All @@ -166,7 +147,6 @@ If only one argument is provided, the assertion passes if `spy` ever threw any e

It's possible to assert on a dedicated spy call: `sinon.assert.threw(spy.thirdCall, exception);`.


#### `sinon.assert.alwaysThrew(spy, exception);`

Like above, only required for all calls to the spy.
Expand All @@ -176,15 +156,15 @@ Like above, only required for all calls to the spy.
Uses [`sinon.match`](../matchers) to test if the arguments can be considered a match.

```javascript
var sinon = require('sinon');
var sinon = require("sinon");

describe('example', function(){
it('should match on `x` property, and ignore `y` property', function() {
var expected = {x: 1},
actual = {x: 1, y: 2};
describe("example", function () {
it("should match on `x` property, and ignore `y` property", function () {
var expected = { x: 1 },
actual = { x: 1, y: 2 };

sinon.assert.match(actual, expected);
});
sinon.assert.match(actual, expected);
});
});
```

Expand All @@ -206,4 +186,5 @@ The method accepts an optional options object with two options.

<dt>includeFail</dt>
<dd><code>true</code> by default, copies over the <code>fail</code> and <code>failException</code> properties</dd>

</dl>
4 changes: 2 additions & 2 deletions docs/_releases/latest/examples/spies-1-pubsub.test.js
Expand Up @@ -4,8 +4,8 @@ const PubSub = require("pubsub-js");
const referee = require("@sinonjs/referee");
const assertTrue = referee.assert;

describe("PubSub", function() {
it("should call subscribers on publish", function() {
describe("PubSub", function () {
it("should call subscribers on publish", function () {
const callback = sinon.spy();

PubSub.subscribe("message", callback);
Expand Down
20 changes: 13 additions & 7 deletions docs/_releases/latest/examples/spies-2-wrap-object-methods.test.js
Expand Up @@ -12,27 +12,33 @@ const myExternalLibrary = {
_doNetworkCall(httpParams) {
console.log("Simulating fetching stuff from the network: ", httpParams);
return { result: 42 };
}
},
};

describe("Wrap all object methods", function() {
describe("Wrap all object methods", function () {
const sandbox = sinon.createSandbox();

beforeEach(function() {
beforeEach(function () {
sandbox.spy(myExternalLibrary);
});

afterEach(function() {
afterEach(function () {
sandbox.restore();
});

it("should inspect the external lib's usage of its internal methods", function() {
it("should inspect the external lib's usage of its internal methods", function () {
const url = "https://jsonplaceholder.typicode.com/todos/1";
myExternalLibrary.getJSON(url);

assert(myExternalLibrary.getJSON.calledOnce);
assert(myExternalLibrary._doNetworkCall.calledOnce);
assert.equals(url, myExternalLibrary._doNetworkCall.getCall(0).args[0].url);
assert.equals("json", myExternalLibrary._doNetworkCall.getCall(0).args[0].dataType);
assert.equals(
url,
myExternalLibrary._doNetworkCall.getCall(0).args[0].url
);
assert.equals(
"json",
myExternalLibrary._doNetworkCall.getCall(0).args[0].dataType
);
});
});
Expand Up @@ -10,18 +10,18 @@ const document = new JSDOM("").window;
const jQuery = require("jquery")(window);
global.document = document;

describe("Wrap existing method", function() {
describe("Wrap existing method", function () {
const sandbox = sinon.createSandbox();

beforeEach(function() {
beforeEach(function () {
sandbox.spy(jQuery, "ajax");
});

afterEach(function() {
afterEach(function () {
sandbox.restore();
});

it("should inspect jQuery.getJSON's usage of jQuery.ajax", function() {
it("should inspect jQuery.getJSON's usage of jQuery.ajax", function () {
const url = "https://jsonplaceholder.typicode.com/todos/1";
jQuery.getJSON(url);

Expand Down
Expand Up @@ -5,8 +5,8 @@ const PubSub = require("pubsub-js");
const referee = require("@sinonjs/referee");
const assert = referee.assert;

describe("PubSub", function() {
it("should call subscribers with message as first argument", function() {
describe("PubSub", function () {
it("should call subscribers with message as first argument", function () {
const message = "an example message";
const spy = sinon.spy();

Expand Down
Expand Up @@ -5,8 +5,8 @@ const PubSub = require("pubsub-js");
const referee = require("@sinonjs/referee");
const assert = referee.assert;

describe("PubSub", function() {
it("should call subscribers with message as first argument", function() {
describe("PubSub", function () {
it("should call subscribers with message as first argument", function () {
const message = "an example message";
const spy = sinon.spy();

Expand Down
Expand Up @@ -5,8 +5,8 @@ const PubSub = require("pubsub-js");
const referee = require("@sinonjs/referee");
const assert = referee.assert;

describe("PubSub", function() {
it("should call subscribers with message as first argument", function() {
describe("PubSub", function () {
it("should call subscribers with message as first argument", function () {
const message = "an example message";
const spy = sinon.spy();

Expand Down
4 changes: 2 additions & 2 deletions docs/_releases/latest/examples/spies-7-with-args.test.js
Expand Up @@ -4,8 +4,8 @@ const sinon = require("sinon");
const referee = require("@sinonjs/referee");
const assert = referee.assert;

describe("withArgs", function() {
it("should call method once with each argument", function() {
describe("withArgs", function () {
it("should call method once with each argument", function () {
const object = { method() {} };
const spy = sinon.spy(object, "method");

Expand Down
8 changes: 4 additions & 4 deletions docs/_releases/latest/examples/spies-8-spy-call.test.js
Expand Up @@ -10,18 +10,18 @@ const document = new JSDOM("").window;
const jQuery = require("jquery")(window);
global.document = document;

describe("Return nth call", function() {
describe("Return nth call", function () {
const sandbox = sinon.createSandbox();

beforeEach(function() {
beforeEach(function () {
sandbox.spy(jQuery, "ajax");
});

afterEach(function() {
afterEach(function () {
sandbox.restore();
});

it("should inspect jQuery.getJSON's usage of jQuery.ajax", function() {
it("should inspect jQuery.getJSON's usage of jQuery.ajax", function () {
const url = "https://jsonplaceholder.typicode.com/todos/1";
jQuery.ajax(url);
const spyCall = jQuery.ajax.getCall(0);
Expand Down

0 comments on commit e3b3195

Please sign in to comment.