- Separate out from old mono repository. - Adjust name including new namespace. - Adjust version to pre-1.0
30 lines
882 B
TypeScript
30 lines
882 B
TypeScript
import { passOrYield } from "../unit";
|
|
|
|
class TestError {
|
|
constructor(readonly message: string) {}
|
|
}
|
|
|
|
describe("passOrYield", () => {
|
|
const f = () => new TestError("Assert!");
|
|
it("passes constructed error correctly", () => {
|
|
const e = new TestError("Failed!");
|
|
expect(passOrYield(TestError, f)(e)).toEqual(e);
|
|
});
|
|
|
|
it("handles thrown object", () => {
|
|
try {
|
|
throw new TestError("Thrown!");
|
|
} catch (e) {
|
|
expect(passOrYield(TestError, f)(e)).toEqual(e);
|
|
}
|
|
});
|
|
|
|
it("handles a synthetic error", () => {
|
|
// 3rd party code can mangle our errors but usually produce a descendant
|
|
// of the builtin, Error, and preserve the name from our classes
|
|
// constructor function
|
|
const synthetic = new Error("Synthetic!");
|
|
synthetic.name = TestError.name;
|
|
expect(passOrYield(TestError, f)(synthetic)).toEqual(synthetic);
|
|
});
|
|
});
|