Skip to content

Commit

Permalink
Added further tests to highlight how to test a class method does not …
Browse files Browse the repository at this point in the history
…throw in the throws module.
  • Loading branch information
RobDWaller committed Jun 30, 2020
1 parent 61dced5 commit 837cc65
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/throws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,40 @@ Deno.test("Not Throws", () => {
assertTrue(result.isOk());
});

Deno.test("Not Throws", () => {
Deno.test("Not Throws Fail", () => {
const toThrow = () => {
throw new Error("Error!");
}

const result: Result<string> = notThrows(toThrow);

assertFalse(result.isOk());
});

Deno.test("Not Throws Class", () => {
class AllOk {
ok(): string {
return "Ok";
}
}

const allOk = new AllOk();

const result: Result<string> = notThrows(() => { allOk.ok() });

assertTrue(result.isOk());
});

Deno.test("Not Throws Class Fail", () => {
class NotOk {
notOk(): string {
throw new Error();
}
}

const notOk = new NotOk();

const result: Result<string> = notThrows(() => { notOk.notOk() });

assertFalse(result.isOk());
});

0 comments on commit 837cc65

Please sign in to comment.