Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Oct 31, 2023
1 parent 471e697 commit 17bf8d5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 67 deletions.
6 changes: 3 additions & 3 deletions lib/sinon/default-behaviors.js
Expand Up @@ -33,15 +33,15 @@ function throwsException(fake, error, message) {
const SKIP_OPTIONS_FOR_YIELDS = {
skipReturn: true,
skipThrows: true,
}
};

function clear(fake, options) {
fake.fakeFn = undefined;

fake.callsThrough = undefined;
fake.callsThroughWithNew = undefined;

if(!options || !options.skipThrows) {
if (!options || !options.skipThrows) {
fake.exception = undefined;
fake.exceptionCreator = undefined;
fake.throwArgAt = undefined;
Expand All @@ -53,7 +53,7 @@ function clear(fake, options) {
fake.callArgProp = undefined;
fake.callbackAsync = undefined;

if(!options || !options.skipReturn) {
if (!options || !options.skipReturn) {
fake.returnValue = undefined;
fake.returnValueDefined = undefined;
fake.returnArgAt = undefined;
Expand Down
133 changes: 69 additions & 64 deletions test/stub-test.js
Expand Up @@ -229,9 +229,9 @@ describe("stub", function () {
const obj = {
fn() {
return 1;
}
}
const stub = createStub(obj, 'fn').callThrough().returns(2);
},
};
const stub = createStub(obj, "fn").callThrough().returns(2);

assert.equals(stub(), 2);
});
Expand Down Expand Up @@ -299,14 +299,13 @@ describe("stub", function () {
const obj = {
fn() {
return Promise.resolve(1);
}
}
const stub = createStub(obj, 'fn').callThrough().resolves(2);
},
};
const stub = createStub(obj, "fn").callThrough().resolves(2);

return stub()
.then(function (actual) {
assert.equals(actual, 2);
});
return stub().then(function (actual) {
assert.equals(actual, 2);
});
});

it("supersedes previous callsFake", function () {
Expand Down Expand Up @@ -434,10 +433,10 @@ describe("stub", function () {
const obj = {
fn() {
return Promise.resolve(1);
}
},
};
const reason = new Error();
const stub = createStub(obj, 'fn').callThrough().rejects(reason);
const stub = createStub(obj, "fn").callThrough().rejects(reason);

return stub()
.then(function () {
Expand Down Expand Up @@ -528,14 +527,13 @@ describe("stub", function () {
const obj = {
fn() {
return Promise.resolve(1);
}
},
};
createStub(obj, 'fn').callThrough().resolvesThis();
createStub(obj, "fn").callThrough().resolvesThis();

return obj.fn()
.then(function (actual) {
assert.same(actual, obj);
});
return obj.fn().then(function (actual) {
assert.same(actual, obj);
});
});

it("supersedes previous callsFake", function () {
Expand Down Expand Up @@ -623,15 +621,14 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return Promise.resolve('nooooo');
}
return Promise.resolve("nooooo");
},
};
createStub(obj, 'fn').callThrough().resolvesArg(1);
createStub(obj, "fn").callThrough().resolvesArg(1);

return obj.fn('zero', 'one')
.then(function (actual) {
assert.same(actual, "one");
});
return obj.fn("zero", "one").then(function (actual) {
assert.same(actual, "one");
});
});

it("does not invoke Promise.resolve when the behavior is added to the stub", function () {
Expand Down Expand Up @@ -696,10 +693,10 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
return "nooooo";
},
};
createStub(obj, 'fn').callThrough().returnsArg(0);
createStub(obj, "fn").callThrough().returnsArg(0);

assert.equals(obj.fn("myarg"), "myarg");
});
Expand Down Expand Up @@ -833,10 +830,10 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
return "nooooo";
},
};
createStub(obj, 'fn').callThrough().throwsArg(1);
createStub(obj, "fn").callThrough().throwsArg(1);
const expectedError = new Error("catpants");

assert.exception(
Expand Down Expand Up @@ -905,10 +902,10 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
return "nooooo";
},
};
createStub(obj, 'fn').callThrough().returnsThis();
createStub(obj, "fn").callThrough().returnsThis();

assert.same(obj.fn(), obj);
});
Expand Down Expand Up @@ -1150,11 +1147,11 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
return "nooooo";
},
};
const expectedError = new Error("catpants");
createStub(obj, 'fn').callThrough().throws(expectedError);
createStub(obj, "fn").callThrough().throws(expectedError);

assert.exception(obj.fn, {
message: expectedError.message,
Expand Down Expand Up @@ -1240,10 +1237,10 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
return "nooooo";
},
};
const stub = createStub(obj, 'fn').callThrough().callsArg(0);
const stub = createStub(obj, "fn").callThrough().callsArg(0);

const callback = createStub().returns("return value");

Expand Down Expand Up @@ -1326,10 +1323,12 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
return "nooooo";
},
};
const stub = createStub(obj, 'fn').callThrough().callsArgWith(0, 'test');
const stub = createStub(obj, "fn")
.callThrough()
.callsArgWith(0, "test");
const callback = createStub().returns("return value");

assert.same(stub(callback), "return value");
Expand Down Expand Up @@ -1426,10 +1425,10 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
return "nooooo";
},
};
createStub(obj, 'fn').callThrough().callsArgOn(0, this.fakeContext);
createStub(obj, "fn").callThrough().callsArgOn(0, this.fakeContext);
const callback = createStub().returns("return value");

assert.same(obj.fn(callback), "return value");
Expand Down Expand Up @@ -1562,12 +1561,14 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
return "nooooo";
},
};

const arg = 'hello';
createStub(obj, 'fn').callThrough().callsArgOnWith(1, this.fakeContext, arg);
const arg = "hello";
createStub(obj, "fn")
.callThrough()
.callsArgOnWith(1, this.fakeContext, arg);
const callback = createStub();

obj.fn(1, callback);
Expand Down Expand Up @@ -1632,13 +1633,15 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
return "nooooo";
},
};

createStub(obj, 'fn').callThrough().callsFake(() => 'yeees');
createStub(obj, "fn")
.callThrough()
.callsFake(() => "yeees");

assert.same(obj.fn(), 'yeees');
assert.same(obj.fn(), "yeees");
});
});

Expand Down Expand Up @@ -1941,10 +1944,10 @@ describe("stub", function () {
const obj = {
fn() {
return 1;
}
},
};

createStub(obj, 'fn').callThrough().yields(2);
createStub(obj, "fn").callThrough().yields(2);
const spy = createSpy();
obj.fn(spy);

Expand Down Expand Up @@ -2085,10 +2088,10 @@ describe("stub", function () {
const obj = {
fn() {
return 1;
}
},
};

createStub(obj, 'fn').callThrough().yieldsRight(2);
createStub(obj, "fn").callThrough().yieldsRight(2);
const spy = createSpy();
obj.fn(spy);

Expand Down Expand Up @@ -2256,10 +2259,10 @@ describe("stub", function () {
const obj = {
fn() {
return 1;
}
},
};

createStub(obj, 'fn').callThrough().yieldsOn(this.fakeContext, 2);
createStub(obj, "fn").callThrough().yieldsOn(this.fakeContext, 2);
const spy = createSpy();
obj.fn(spy);

Expand Down Expand Up @@ -2421,10 +2424,10 @@ describe("stub", function () {
const obj = {
fn() {
return 1;
}
},
};

createStub(obj, 'fn').callThrough().yieldsTo("success", 2);
createStub(obj, "fn").callThrough().yieldsTo("success", 2);
const callback = createSpy();
obj.fn({ success: callback });

Expand Down Expand Up @@ -2621,10 +2624,12 @@ describe("stub", function () {
const obj = {
fn() {
return 1;
}
},
};

createStub(obj, 'fn').callThrough().yieldsToOn("success", this.fakeContext, 2);
createStub(obj, "fn")
.callThrough()
.yieldsToOn("success", this.fakeContext, 2);
const callback = createSpy();
obj.fn({ success: callback });

Expand Down

0 comments on commit 17bf8d5

Please sign in to comment.