Skip to content

Commit b901a02

Browse files
committed
Add release documentation for v11.1.0
1 parent b91c955 commit b901a02

File tree

74 files changed

+4172
-88
lines changed

Some content is hidden

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

74 files changed

+4172
-88
lines changed

docs/_releases/latest.md

Lines changed: 2 additions & 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: v11.0.0
5+
release_id: v11.1.0
66
---
77

88
# {{page.title}} - `{{page.release_id}}`
@@ -15,6 +15,7 @@ This page contains the entire Sinon.JS API documentation along with brief introd
1515
- [Stubs](./stubs)
1616
- [Mocks](./mocks)
1717
- [Spy calls](./spy-call)
18+
- [Promises](./promises)
1819
- [Fake timers](./fake-timers)
1920
- [Fake <code>XHR</code> and server](./fake-xhr-and-server)
2021
- [JSON-P](./json-p)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should be able to be used instead of spies", function () {
8+
const foo = {
9+
bar: () => "baz",
10+
};
11+
// wrap existing method without changing its behaviour
12+
const fake = sinon.replace(foo, "bar", sinon.fake(foo.bar));
13+
14+
assert.equals(fake(), "baz"); // behaviour is the same
15+
assert.equals(fake.callCount, 1); // calling information is saved
16+
});
17+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should have working firstArg property", function () {
8+
const f = sinon.fake();
9+
const date1 = new Date();
10+
const date2 = new Date();
11+
12+
f(date1, 1, 2);
13+
f(date2, 1, 2);
14+
15+
assert.isTrue(f.firstArg === date2);
16+
});
17+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should have working lastArg property", function () {
8+
const f = sinon.fake();
9+
const date1 = new Date();
10+
const date2 = new Date();
11+
12+
f(1, 2, date1);
13+
f(1, 2, date2);
14+
15+
assert.isTrue(f.lastArg === date2);
16+
// spy call methods:
17+
assert.isTrue(f.getCall(0).lastArg === date1);
18+
assert.isTrue(f.getCall(1).lastArg === date2);
19+
assert.isTrue(f.lastCall.lastArg === date2);
20+
});
21+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should have working lastArg property", function () {
8+
const fake = sinon.fake.returns("42");
9+
10+
sinon.replace(console, "log", fake);
11+
12+
assert.equals(console.log("apple pie"), 42);
13+
14+
// restores all replaced properties set by sinon methods (replace, spy, stub)
15+
sinon.restore();
16+
17+
assert.equals(console.log("apple pie"), undefined);
18+
assert.equals(fake.callCount, 1);
19+
});
20+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should be able to be used instead of stubs", function () {
8+
const foo = {
9+
bar: () => "baz",
10+
};
11+
// replace method with a fake one
12+
const fake = sinon.replace(
13+
foo,
14+
"bar",
15+
sinon.fake.returns("fake value")
16+
);
17+
18+
assert.equals(fake(), "fake value"); // returns fake value
19+
assert.equals(fake.callCount, 1); // saves calling information
20+
});
21+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should create fake without behaviour", function () {
8+
// create a basic fake, with no behavior
9+
const fake = sinon.fake();
10+
11+
assert.isUndefined(fake()); // by default returns undefined
12+
assert.equals(fake.callCount, 1); // saves call information
13+
});
14+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should create fake with custom behaviour", function () {
8+
// create a fake that returns the text "foo"
9+
const fake = sinon.fake.returns("foo");
10+
11+
assert.equals(fake(), "foo");
12+
});
13+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should create a fake that 'returns' a value", function () {
8+
const fake = sinon.fake.returns("apple pie");
9+
10+
assert.equals(fake(), "apple pie");
11+
});
12+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should create a fake that 'throws' an Error", function () {
8+
const fake = sinon.fake.throws(new Error("not apple pie"));
9+
10+
// Expected to throw an error with message 'not apple pie'
11+
assert.exception(fake, { name: "Error", message: "not apple pie" });
12+
});
13+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
const fs = require("fs");
6+
7+
describe("FakeTest", function () {
8+
it("should create a fake that 'yields'", function () {
9+
const fake = sinon.fake.yields(null, "file content");
10+
const anotherFake = sinon.fake();
11+
12+
sinon.replace(fs, "readFile", fake);
13+
fs.readFile("somefile", (err, data) => {
14+
// called with fake values given to yields as arguments
15+
assert.isNull(err);
16+
assert.equals(data, "file content");
17+
// since yields is synchronous, anotherFake is not called yet
18+
assert.isFalse(anotherFake.called);
19+
});
20+
21+
anotherFake();
22+
});
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
const fs = require("fs");
6+
7+
describe("FakeTest", function () {
8+
it("should create a fake that 'yields asynchronously'", function () {
9+
const fake = sinon.fake.yieldsAsync(null, "file content");
10+
const anotherFake = sinon.fake();
11+
12+
sinon.replace(fs, "readFile", fake);
13+
fs.readFile("somefile", (err, data) => {
14+
// called with fake values given to yields as arguments
15+
assert.isNull(err);
16+
assert.equals(data, "file content");
17+
// since yields is asynchronous, anotherFake is called first
18+
assert.isTrue(anotherFake.called);
19+
});
20+
21+
anotherFake();
22+
});
23+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require("@fatso83/mini-mocha").install();
2+
const sinon = require("sinon");
3+
const referee = require("@sinonjs/referee");
4+
const assert = referee.assert;
5+
6+
describe("FakeTest", function () {
7+
it("should have working callback property", function () {
8+
const f = sinon.fake();
9+
const cb1 = function () {};
10+
const cb2 = function () {};
11+
12+
f(1, 2, 3, cb1);
13+
f(1, 2, 3, cb2);
14+
15+
assert.isTrue(f.callback === cb2);
16+
// spy call methods:
17+
assert.isTrue(f.getCall(1).callback === cb2);
18+
assert.isTrue(f.lastCall.callback === cb2);
19+
});
20+
});

docs/_releases/latest/examples/run-test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/bin/bash
2-
32
# Link 'sinon' to local development dir
43
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5-
cd "$SCRIPT_DIR/.."
4+
SINON_ROOT="$SCRIPT_DIR/../../../.."
5+
6+
cd "$SINON_ROOT"
67
npm link
78

89
# Install examples project and link to local sinon folder
910
cd "$SCRIPT_DIR"
11+
rm -r node_modules 2>/dev/null
1012
npm install --ignore-scripts
1113
npm link sinon
1214

0 commit comments

Comments
 (0)