|
| 1 | +import { suite } from "uvu"; |
| 2 | +import assert from "uvu/assert"; |
| 3 | + |
| 4 | +import { wrapper } from "./wrapper.ts"; |
| 5 | + |
| 6 | +{ |
| 7 | + const test = suite("wrapper"); |
| 8 | + |
| 9 | + test("exports `wrapper`", () => { |
| 10 | + assert.ok(wrapper); |
| 11 | + }); |
| 12 | + |
| 13 | + test("that `wrapper` is function", () => { |
| 14 | + assert.instance(wrapper, Function); |
| 15 | + }); |
| 16 | + |
| 17 | + test("doesn't throw with sync success action", () => { |
| 18 | + class TestStore { |
| 19 | + constructor() { |
| 20 | + return wrapper(this as any); |
| 21 | + } |
| 22 | + public test() {} |
| 23 | + } |
| 24 | + const testStore = new TestStore(); |
| 25 | + |
| 26 | + assert.not.throws(testStore.test); |
| 27 | + }); |
| 28 | + |
| 29 | + test("doesn't throw with async success action", async () => { |
| 30 | + class TestStore { |
| 31 | + constructor() { |
| 32 | + return wrapper(this as any); |
| 33 | + } |
| 34 | + public async test() { |
| 35 | + await Promise.resolve(); |
| 36 | + } |
| 37 | + } |
| 38 | + const testStore = new TestStore(); |
| 39 | + |
| 40 | + try { |
| 41 | + await testStore.test(); |
| 42 | + assert.ok(true); |
| 43 | + } catch (err) { |
| 44 | + assert.instance(err, Error); |
| 45 | + assert.equal(err.message, "test error"); |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + test("throws with sync error action", () => { |
| 50 | + class TestStore { |
| 51 | + constructor() { |
| 52 | + return wrapper(this as any); |
| 53 | + } |
| 54 | + public test() { |
| 55 | + throw new Error("test error"); |
| 56 | + } |
| 57 | + } |
| 58 | + const testStore = new TestStore(); |
| 59 | + |
| 60 | + assert.throws(testStore.test); |
| 61 | + }); |
| 62 | + |
| 63 | + test("throws with async error action", async () => { |
| 64 | + class TestStore { |
| 65 | + constructor() { |
| 66 | + return wrapper(this as any); |
| 67 | + } |
| 68 | + public async test() { |
| 69 | + await Promise.resolve(); |
| 70 | + throw new Error("test error"); |
| 71 | + } |
| 72 | + } |
| 73 | + const testStore = new TestStore(); |
| 74 | + |
| 75 | + try { |
| 76 | + await testStore.test(); |
| 77 | + assert.unreachable(); |
| 78 | + } catch (err) { |
| 79 | + assert.instance(err, Error); |
| 80 | + assert.equal(err.message, "test error"); |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + test.run(); |
| 85 | +} |
0 commit comments