Skip to content

Commit

Permalink
Add tests for toHaveNthReturnedWith
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRamosAcosta committed May 9, 2020
1 parent fee1483 commit bf6e5e8
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion matchers_test.ts
Expand Up @@ -32,6 +32,7 @@ import {
toHaveReturned,
toHaveLastReturnedWith,
toHaveReturnedTimes,
toHaveNthReturnedWith,
} from "./matchers.ts";

function assertResult(actual: MatchResult, expected: MatchResult) {
Expand Down Expand Up @@ -686,4 +687,32 @@ Deno.test({
},
});

//TODO(allain) - toHaveNthReturnedWith(value: any, nth: number, expected: any): MatchResult
Deno.test({
name: "toHaveNthReturnedWithPass",
fn: () => {
const m = mock.fn((n: number) => n);
m(1);
m(2);
m(3);
const nthCall = 2;
assertResultPass(toHaveNthReturnedWith(m, nthCall, 2));
},
});

Deno.test({
name: "toHaveNthReturnedWithFail",
fn: () => {
const m = mock.fn((n: number) => n);
m(1);
m(2);
m(3);
assertResult(toHaveNthReturnedWith(m, 2, 1), {
pass: false,
message: `expected 2th call to return 1 but returned: 2`,
});
assertResult(toHaveNthReturnedWith(m, 9, 1), {
pass: false,
message: `9 calls were now made`,
});
},
});

0 comments on commit bf6e5e8

Please sign in to comment.