Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add factory functions for sandbox and fake server
This adds the following methods as aliases:

- createSandbox = sandbox.create
- createFakeServer = fakeServer.create
- createFakeServerWithClock = fakeServerWithClock.create
  • Loading branch information
mantoni committed Aug 6, 2017
1 parent ec74e94 commit 4c2aa41
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
8 changes: 7 additions & 1 deletion lib/sinon.js
Expand Up @@ -7,7 +7,9 @@ exports.spy = require("./sinon/spy");
exports.spyCall = require("./sinon/call");
exports.stub = require("./sinon/stub");
exports.mock = require("./sinon/mock");
exports.sandbox = require("./sinon/sandbox");

var sandbox = require("./sinon/sandbox");
exports.sandbox = sandbox;
exports.expectation = require("./sinon/mock-expectation");
exports.createStubInstance = require("./sinon/stub").createStubInstance;

Expand All @@ -26,6 +28,10 @@ exports.useFakeXMLHttpRequest = nise.fakeXhr.useFakeXMLHttpRequest;
exports.fakeServer = nise.fakeServer;
exports.fakeServerWithClock = nise.fakeServerWithClock;

exports.createSandbox = sandbox.create;
exports.createFakeServer = nise.fakeServer.create;
exports.createFakeServerWithClock = nise.fakeServerWithClock.create;

var behavior = require("./sinon/behavior");

exports.addBehavior = function (name, fn) {
Expand Down
37 changes: 32 additions & 5 deletions test/sinon-test.js
Expand Up @@ -10,34 +10,61 @@ if (!hasPromise) {

describe("sinon module", function () {
var sinon,
fakeSandbox,
fakeNise;

beforeEach(function () {

fakeNise = {
fakeServer: "47c86a4c-6b48-4748-bb8c-d853f999720c",
fakeServerWithClock: "e69974f8-4568-48d1-a5e9-2b511a59c14b",
fakeServer: {
create: "47c86a4c-6b48-4748-bb8c-d853f999720c"
},
fakeServerWithClock: {
create: "e69974f8-4568-48d1-a5e9-2b511a59c14b"
},
fakeXhr: {
xhr: "958e8996-0cc3-4136-8a0e-6a120f5311bc",
FakeXMLHttpRequest: "6adbf569-f6d7-4b86-be22-38340ae0f8c8",
useFakeXMLHttpRequest: "ba8bd609-c921-4a62-a1b9-49336bd426a4"
}
};
fakeSandbox = {
create: "dc61d622-407f-46eb-af24-7a83bb30b8bf"
};
sinon = proxyquire("../lib/sinon", {
nise: fakeNise
nise: fakeNise,
"./sinon/sandbox": fakeSandbox
});
});

describe("exports", function () {
describe("createSandbox", function () {
it("should be sandbox.create", function () {
assert.equals(sinon.createSandbox, fakeSandbox.create);
});
});

describe("fakeServer", function () {
it("should be the fakeServer export from nise", function () {
assert.equals(sinon.fakeServer, fakeNise.fakeServer);
assert.same(sinon.fakeServer, fakeNise.fakeServer);
});
});

describe("createFakeServer", function () {
it("should be fakeServer.create from nise", function () {
assert.equals(sinon.createFakeServer, fakeNise.fakeServer.create);
});
});

describe("fakeServerWithClock", function () {
it("should be the fakeServerWithClock export from nise", function () {
assert.equals(sinon.fakeServerWithClock, fakeNise.fakeServerWithClock);
assert.same(sinon.fakeServerWithClock, fakeNise.fakeServerWithClock);
});
});

describe("createFakeServerWithClock", function () {
it("should be fakeServerWithClock.create from nise", function () {
assert.equals(sinon.createFakeServerWithClock, fakeNise.fakeServerWithClock.create);
});
});

Expand Down

0 comments on commit 4c2aa41

Please sign in to comment.