Skip to content

Commit

Permalink
feat(option): test cov
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsasharegan committed Feb 13, 2018
1 parent 6709ba2 commit 5de95c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/__snapshots__/option.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Option.unwrap should throw Error with None 1`] = `[Error: called \`Option.unwrap()\` on a \`None\` value]`;
23 changes: 20 additions & 3 deletions src/option.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,27 @@ describe("None", async () => {
});
});

describe("Option.from", async () => {
describe("Option.from && Option.of", async () => {
it("should be None when given undefined value", async () => {
let x: number;
let o = Option.from(x);
expect(o.is_none()).toBe(true);
expect(o.is_some()).toBe(false);

o = Option.of(x);
expect(o.is_none()).toBe(true);
expect(o.is_some()).toBe(false);
});

it("should be Some when given a value", async () => {
let x = 10;
let o = Option.from(x);
expect(o.is_none()).toBe(false);
expect(o.is_some()).toBe(true);

o = Option.of(x);
expect(o.is_none()).toBe(false);
expect(o.is_some()).toBe(true);
});
});

Expand All @@ -58,10 +66,19 @@ describe("Option.unwrap", async () => {
expect(o.unwrap()).toBe(10);
});

it("should throw TypeError with None", async () => {
it("should throw Error with None", async () => {
let x: number;
let o = Option.from(x);
expect(o.unwrap).toThrow(TypeError);
expect(o.unwrap).toThrow(Error);

let err;
try {
o.unwrap();
} catch (e) {
err = e;
}

expect(err).toMatchSnapshot();
});
});

Expand Down

0 comments on commit 5de95c8

Please sign in to comment.