diff options
Diffstat (limited to 'tests/js/utils.mjs')
-rw-r--r-- | tests/js/utils.mjs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/js/utils.mjs b/tests/js/utils.mjs index 94e8eae..e4f21d0 100644 --- a/tests/js/utils.mjs +++ b/tests/js/utils.mjs @@ -9,6 +9,7 @@ import { getIn, first, log, + promisify, } from "../../src/utils.mjs"; const test_eq = t => { @@ -258,6 +259,37 @@ const test_log = t => { }); }; +const test_promisify = t => { + t.start("promisify()"); + + t.test("we wrap the callbacky function", async () => { + const okFn1 = (a, b, cb) => + setTimeout(() => cb(null, { a, b, ok: true })); + const errFn1 = (a, b, c, cb) => + setTimeout(() => cb({ err: true, a }, "ignored")); + + const okFn2 = promisify(okFn1); + const errFn2 = promisify(errFn1); + + assert.deepEqual( + await okFn2("a-value", "b-value"), + { + a: "a-value", + b: "b-value", + ok: true, + }, + ); + + assert.rejects( + async () => await errFn2("aa", "bb", "cc"), + { + err: true, + a: "aa", + }, + ); + }); +}; + await runTests([ test_eq, @@ -267,4 +299,5 @@ await runTests([ test_getIn, test_first, test_log, + test_promisify, ]); |