-
-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add release documentation for v11.1.0
- Loading branch information
Showing
74 changed files
with
4,172 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
docs/_releases/latest/examples/fakes-1-using-fakes-instead-of-spies.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should be able to be used instead of spies", function () { | ||
const foo = { | ||
bar: () => "baz", | ||
}; | ||
// wrap existing method without changing its behaviour | ||
const fake = sinon.replace(foo, "bar", sinon.fake(foo.bar)); | ||
|
||
assert.equals(fake(), "baz"); // behaviour is the same | ||
assert.equals(fake.callCount, 1); // calling information is saved | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should have working firstArg property", function () { | ||
const f = sinon.fake(); | ||
const date1 = new Date(); | ||
const date2 = new Date(); | ||
|
||
f(date1, 1, 2); | ||
f(date2, 1, 2); | ||
|
||
assert.isTrue(f.firstArg === date2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should have working lastArg property", function () { | ||
const f = sinon.fake(); | ||
const date1 = new Date(); | ||
const date2 = new Date(); | ||
|
||
f(1, 2, date1); | ||
f(1, 2, date2); | ||
|
||
assert.isTrue(f.lastArg === date2); | ||
// spy call methods: | ||
assert.isTrue(f.getCall(0).lastArg === date1); | ||
assert.isTrue(f.getCall(1).lastArg === date2); | ||
assert.isTrue(f.lastCall.lastArg === date2); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
docs/_releases/latest/examples/fakes-12-adding-fake-to-system-under-test.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should have working lastArg property", function () { | ||
const fake = sinon.fake.returns("42"); | ||
|
||
sinon.replace(console, "log", fake); | ||
|
||
assert.equals(console.log("apple pie"), 42); | ||
|
||
// restores all replaced properties set by sinon methods (replace, spy, stub) | ||
sinon.restore(); | ||
|
||
assert.equals(console.log("apple pie"), undefined); | ||
assert.equals(fake.callCount, 1); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
docs/_releases/latest/examples/fakes-2-using-fakes-instead-of-stubs.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should be able to be used instead of stubs", function () { | ||
const foo = { | ||
bar: () => "baz", | ||
}; | ||
// replace method with a fake one | ||
const fake = sinon.replace( | ||
foo, | ||
"bar", | ||
sinon.fake.returns("fake value") | ||
); | ||
|
||
assert.equals(fake(), "fake value"); // returns fake value | ||
assert.equals(fake.callCount, 1); // saves calling information | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
docs/_releases/latest/examples/fakes-3-creating-without-behaviour.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should create fake without behaviour", function () { | ||
// create a basic fake, with no behavior | ||
const fake = sinon.fake(); | ||
|
||
assert.isUndefined(fake()); // by default returns undefined | ||
assert.equals(fake.callCount, 1); // saves call information | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
docs/_releases/latest/examples/fakes-4-creating-with-custom-behaviour.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should create fake with custom behaviour", function () { | ||
// create a fake that returns the text "foo" | ||
const fake = sinon.fake.returns("foo"); | ||
|
||
assert.equals(fake(), "foo"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should create a fake that 'returns' a value", function () { | ||
const fake = sinon.fake.returns("apple pie"); | ||
|
||
assert.equals(fake(), "apple pie"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should create a fake that 'throws' an Error", function () { | ||
const fake = sinon.fake.throws(new Error("not apple pie")); | ||
|
||
// Expected to throw an error with message 'not apple pie' | ||
assert.exception(fake, { name: "Error", message: "not apple pie" }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
const fs = require("fs"); | ||
|
||
describe("FakeTest", function () { | ||
it("should create a fake that 'yields'", function () { | ||
const fake = sinon.fake.yields(null, "file content"); | ||
const anotherFake = sinon.fake(); | ||
|
||
sinon.replace(fs, "readFile", fake); | ||
fs.readFile("somefile", (err, data) => { | ||
// called with fake values given to yields as arguments | ||
assert.isNull(err); | ||
assert.equals(data, "file content"); | ||
// since yields is synchronous, anotherFake is not called yet | ||
assert.isFalse(anotherFake.called); | ||
}); | ||
|
||
anotherFake(); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
docs/_releases/latest/examples/fakes-8-yields-async.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
const fs = require("fs"); | ||
|
||
describe("FakeTest", function () { | ||
it("should create a fake that 'yields asynchronously'", function () { | ||
const fake = sinon.fake.yieldsAsync(null, "file content"); | ||
const anotherFake = sinon.fake(); | ||
|
||
sinon.replace(fs, "readFile", fake); | ||
fs.readFile("somefile", (err, data) => { | ||
// called with fake values given to yields as arguments | ||
assert.isNull(err); | ||
assert.equals(data, "file content"); | ||
// since yields is asynchronous, anotherFake is called first | ||
assert.isTrue(anotherFake.called); | ||
}); | ||
|
||
anotherFake(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
describe("FakeTest", function () { | ||
it("should have working callback property", function () { | ||
const f = sinon.fake(); | ||
const cb1 = function () {}; | ||
const cb2 = function () {}; | ||
|
||
f(1, 2, 3, cb1); | ||
f(1, 2, 3, cb2); | ||
|
||
assert.isTrue(f.callback === cb2); | ||
// spy call methods: | ||
assert.isTrue(f.getCall(1).callback === cb2); | ||
assert.isTrue(f.lastCall.callback === cb2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.