Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Oct 31, 2023
1 parent 9ae7afb commit 471e697
Showing 1 changed file with 116 additions and 3 deletions.
119 changes: 116 additions & 3 deletions test/stub-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return'nooooo';
return 'nooooo';
}
};
createStub(obj, 'fn').callThrough().returnsThis();
Expand Down Expand Up @@ -1240,7 +1240,7 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return'nooooo';
return 'nooooo';
}
};
const stub = createStub(obj, 'fn').callThrough().callsArg(0);
Expand Down Expand Up @@ -1326,7 +1326,7 @@ describe("stub", function () {
it("supersedes previous callThrough", function () {
const obj = {
fn() {
return'nooooo';
return 'nooooo';
}
};
const stub = createStub(obj, 'fn').callThrough().callsArgWith(0, 'test');
Expand Down Expand Up @@ -1422,6 +1422,20 @@ describe("stub", function () {
assert(callback.calledOnce);
assert(callback.calledOn(this.fakeContext));
});

it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
};
createStub(obj, 'fn').callThrough().callsArgOn(0, this.fakeContext);
const callback = createStub().returns("return value");

assert.same(obj.fn(callback), "return value");
assert(callback.calledOnce);
assert(callback.calledOn(this.fakeContext));
});
});

describe(".callsArgOnWith", function () {
Expand Down Expand Up @@ -1544,6 +1558,23 @@ describe("stub", function () {
assert(callback.calledOnce);
assert(callback.calledWith(object));
});

it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
};

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

obj.fn(1, callback);

assert(callback.calledWith(arg));
assert(callback.calledOn(this.fakeContext));
});
});

describe(".callsFake", function () {
Expand Down Expand Up @@ -1597,6 +1628,18 @@ describe("stub", function () {
assert(fakeFn.called);
assert(returned === 5);
});

it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 'nooooo';
}
};

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

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

describe(".objectMethod", function () {
Expand Down Expand Up @@ -1893,6 +1936,20 @@ describe("stub", function () {
assert(spy.calledWith, 2);
refute(fakeFn.called);
});

it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 1;
}
};

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

assert(spy.calledWith, 2);
});
});

describe(".yieldsRight", function () {
Expand Down Expand Up @@ -2023,6 +2080,20 @@ describe("stub", function () {
assert(spy.calledWith, 2);
refute(fakeFn.called);
});

it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 1;
}
};

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

assert(spy.calledWith, 2);
});
});

describe(".yieldsOn", function () {
Expand Down Expand Up @@ -2180,6 +2251,20 @@ describe("stub", function () {
assert(spy.calledWith, 2);
refute(fakeFn.called);
});

it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 1;
}
};

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

assert(spy.calledWith, 2);
});
});

describe(".yieldsTo", function () {
Expand Down Expand Up @@ -2331,6 +2416,20 @@ describe("stub", function () {
assert(callback.calledWith(2));
refute(fakeFn.called);
});

it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 1;
}
};

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

assert(callback.calledWith, 2);
});
});

describe(".yieldsToOn", function () {
Expand Down Expand Up @@ -2517,6 +2616,20 @@ describe("stub", function () {
assert(callback.calledWith(2));
refute(fakeFn.called);
});

it("supersedes previous callThrough", function () {
const obj = {
fn() {
return 1;
}
};

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

assert(callback.calledWith(2));
});
});

describe(".withArgs", function () {
Expand Down

0 comments on commit 471e697

Please sign in to comment.