diff options
Diffstat (limited to 'tests/js/utils.mjs')
-rw-r--r-- | tests/js/utils.mjs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/js/utils.mjs b/tests/js/utils.mjs index 178f6c8..d16bae8 100644 --- a/tests/js/utils.mjs +++ b/tests/js/utils.mjs @@ -11,6 +11,7 @@ import { promisify, partial, strSortFn, + undefinedAsNull, } from "../../src/utils.mjs"; const test_eq = t => { @@ -361,6 +362,24 @@ const test_strSortFn = t => { }); }; +const test_undefinedAsNull = t => { + t.start("undefinedAsNull()"); + + t.test("null for undefined or null", () => { + assert.equal(undefinedAsNull(undefined), null); + assert.equal(undefinedAsNull(null), null); + }); + + t.test("identity otherwise", () => { + const expected = [ + " ", "", 0, 1, -1.1, true, false, + [], [ "" ], {}, { k: "v" }, + ]; + const given = expected.map(undefinedAsNull); + assert.deepEqual(given, expected); + }); +}; + await runner.runTests([ test_eq, @@ -372,4 +391,5 @@ await runner.runTests([ test_promisify, test_partial, test_strSortFn, + test_undefinedAsNull, ]); |