-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly re-throw errors from async actions
- Loading branch information
Showing
7 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# Changelog | ||
|
||
## 2.4.1 | ||
|
||
### Bugfix | ||
* Properly re-throw errors from async actions. | ||
|
||
## 2.4.0 | ||
|
||
### Feature | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { suite } from "uvu"; | ||
import assert from "uvu/assert"; | ||
|
||
import { wrapper } from "./wrapper.ts"; | ||
|
||
{ | ||
const test = suite("wrapper"); | ||
|
||
test("exports `wrapper`", () => { | ||
assert.ok(wrapper); | ||
}); | ||
|
||
test("that `wrapper` is function", () => { | ||
assert.instance(wrapper, Function); | ||
}); | ||
|
||
test("doesn't throw with sync success action", () => { | ||
class TestStore { | ||
constructor() { | ||
return wrapper(this as any); | ||
} | ||
public test() {} | ||
} | ||
const testStore = new TestStore(); | ||
|
||
assert.not.throws(testStore.test); | ||
}); | ||
|
||
test("doesn't throw with async success action", async () => { | ||
class TestStore { | ||
constructor() { | ||
return wrapper(this as any); | ||
} | ||
public async test() { | ||
await Promise.resolve(); | ||
} | ||
} | ||
const testStore = new TestStore(); | ||
|
||
try { | ||
await testStore.test(); | ||
assert.ok(true); | ||
} catch (err) { | ||
assert.instance(err, Error); | ||
assert.equal(err.message, "test error"); | ||
} | ||
}); | ||
|
||
test("throws with sync error action", () => { | ||
class TestStore { | ||
constructor() { | ||
return wrapper(this as any); | ||
} | ||
public test() { | ||
throw new Error("test error"); | ||
} | ||
} | ||
const testStore = new TestStore(); | ||
|
||
assert.throws(testStore.test); | ||
}); | ||
|
||
test("throws with async error action", async () => { | ||
class TestStore { | ||
constructor() { | ||
return wrapper(this as any); | ||
} | ||
public async test() { | ||
await Promise.resolve(); | ||
throw new Error("test error"); | ||
} | ||
} | ||
const testStore = new TestStore(); | ||
|
||
try { | ||
await testStore.test(); | ||
assert.unreachable(); | ||
} catch (err) { | ||
assert.instance(err, Error); | ||
assert.equal(err.message, "test error"); | ||
} | ||
}); | ||
|
||
test.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters