-
-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix failing test * Flatten fake tests and restore sort order * cleanup * Update docs to reflect new structure * Fix formatting
- Loading branch information
Showing
24 changed files
with
183 additions
and
213 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
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
15 changes: 15 additions & 0 deletions
15
docs/release-source/release/examples/fakes-01-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,15 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
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 | ||
}); |
15 changes: 15 additions & 0 deletions
15
docs/release-source/release/examples/fakes-02-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,15 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
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 | ||
}); |
12 changes: 12 additions & 0 deletions
12
docs/release-source/release/examples/fakes-03-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,12 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
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 | ||
}); |
11 changes: 11 additions & 0 deletions
11
docs/release-source/release/examples/fakes-04-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,11 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
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"); | ||
}); |
10 changes: 10 additions & 0 deletions
10
docs/release-source/release/examples/fakes-05-returns.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,10 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
it("should create a fake that 'returns'", function () { | ||
const fake = sinon.fake.returns("apple pie"); | ||
|
||
assert.equals(fake(), "apple pie"); | ||
}); |
11 changes: 11 additions & 0 deletions
11
docs/release-source/release/examples/fakes-06-throws.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,11 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
it("should create a fake that 'throws'", 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" }); | ||
}); |
23 changes: 23 additions & 0 deletions
23
docs/release-source/release/examples/fakes-07-yields.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"); | ||
|
||
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); | ||
|
||
sinon.restore(); | ||
}); | ||
|
||
anotherFake(); | ||
}); |
23 changes: 23 additions & 0 deletions
23
docs/release-source/release/examples/fakes-08-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"); | ||
|
||
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); | ||
|
||
sinon.restore(); | ||
}); | ||
|
||
anotherFake(); | ||
}); |
18 changes: 18 additions & 0 deletions
18
docs/release-source/release/examples/fakes-09-callback.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,18 @@ | ||
require("@fatso83/mini-mocha").install(); | ||
const sinon = require("sinon"); | ||
const referee = require("@sinonjs/referee"); | ||
const assert = referee.assert; | ||
|
||
it("should have working callback", 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); | ||
}); |
17 changes: 0 additions & 17 deletions
17
docs/release-source/release/examples/fakes-1-using-fakes-instead-of-spies.test.js
This file was deleted.
Oops, something went wrong.
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
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
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
21 changes: 0 additions & 21 deletions
21
docs/release-source/release/examples/fakes-2-using-fakes-instead-of-stubs.test.js
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
docs/release-source/release/examples/fakes-3-creating-without-behaviour.test.js
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
docs/release-source/release/examples/fakes-4-creating-with-custom-behaviour.test.js
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
docs/release-source/release/examples/fakes-5-returns.test.js
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
docs/release-source/release/examples/fakes-6-throws.test.js
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
docs/release-source/release/examples/fakes-7-yields.test.js
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
docs/release-source/release/examples/fakes-8-yields-async.test.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.