Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bkiac committed Jul 9, 2024
1 parent 7e75c24 commit 183997d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"build:ts": "tsc --p ./cfg/tsconfig.types.json",
"format": "prettier --write .",
"format:check": "prettier --check .",
"prepublishOnly": "pnpm run build",
"prepublishOnly": "pnpm run build && pnpm run test",
"test": "pnpm test:ts&& pnpm test:node --run && pnpm test:browser --run",
"test:browser": "vitest --config ./cfg/vitest.browser.config.ts",
"test:node": "vitest --config ./cfg/vitest.config.ts",
"test:ts": "tsc --project ./cfg/tsconfig.test.json",
Expand Down
2 changes: 1 addition & 1 deletion src/async_option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class AsyncOption<T> implements PromiseLike<Option<T>> {
/**
* Async version of `Option#unwrap`.
*/
async unwrap(): Promise<T> {
async unwrap(): Promise<T | undefined> {
return (await this).unwrap();
}

Expand Down
4 changes: 2 additions & 2 deletions src/async_result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ export class AsyncResult<T, E> implements PromiseLike<Result<T, E>> {
/**
* Async version of `Result#unwrap`.
*/
async unwrap(): Promise<T> {
async unwrap(): Promise<T | undefined> {
return (await this).unwrap();
}

/**
* Async version of `Result#unwrapErr`.
*/
async unwrapErr(): Promise<E> {
async unwrapErr(): Promise<E | undefined> {
return (await this).unwrapErr();
}

Expand Down
4 changes: 2 additions & 2 deletions test/async_option.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ describe.concurrent("unwrap", () => {
await expect(option.unwrap()).resolves.toEqual(42);
});

it("throws Panic when called on a None option", async () => {
it("returns undefined when called on a None option", async () => {
const option = promiseNone();
await expect(() => option.unwrap()).rejects.toThrow(Panic);
await expect(option.unwrap()).resolves.toEqual(undefined);
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/async_result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ describe.concurrent("unwrap", () => {
await expect(result.unwrap()).resolves.toEqual(42);
});

it("throws a Panic for an Err result", async () => {
it("returns undefined for an Err result", async () => {
const error = new Error("Test error");
const result = new AsyncResult(Promise.resolve(Err(error)));
await expect(result.unwrap()).rejects.toThrow(Panic);
await expect(result.unwrap()).resolves.toEqual(undefined);
});
});

Expand All @@ -374,9 +374,9 @@ describe.concurrent("unwrapErr", () => {
await expect(result.unwrapErr()).resolves.toEqual(error);
});

it("throws for an Ok result", async () => {
it("returns undefined for an Ok result", async () => {
const result = new AsyncResult(Promise.resolve(Ok(42)));
await expect(result.unwrapErr()).rejects.toThrow(Panic);
await expect(result.unwrapErr()).resolves.toEqual(undefined);
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/option.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ describe.concurrent("unwrap", () => {
expect(option.unwrap()).toEqual(42);
});

it("throws when called on a None option", () => {
it("returns undefined when called on a None option", () => {
const option = TestNone<string>();
expect(() => option.unwrap()).toThrow(Panic);
expect(option.unwrap()).toEqual(undefined);
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ describe.concurrent("unwrap", () => {
expect(result.unwrap()).toEqual(42);
});

it("throws a Panic for an Err result", () => {
it("returns undefined for an Err result", () => {
const result = TestErr<number, string>("error");
expect(() => result.unwrap()).toThrow(Panic);
expect(result.unwrap()).toEqual(undefined);
});
});

Expand All @@ -457,9 +457,9 @@ describe.concurrent("unwrapErr", () => {
expect(result.unwrapErr()).toEqual("error");
});

it("throws for an Ok result", () => {
it("returns undefined for an Ok result", () => {
const result = TestOk<number, string>(42);
expect(() => result.unwrapErr()).toThrow(Panic);
expect(result.unwrapErr()).toEqual(undefined);
});
});

Expand Down

0 comments on commit 183997d

Please sign in to comment.