diff options
author | EuAndreh <eu@euandre.org> | 2024-02-28 11:37:30 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-02-28 11:37:30 -0300 |
commit | 1a8d3599f955668d94ea562a1d0eafd3ac74871b (patch) | |
tree | 4f6827fa7db37bd2bd4e5645f4b316b758ff1ecf /tests/js/utils.mjs | |
parent | src/utils.mjs: Define strSortFn() and use it on all files (diff) | |
download | papod-1a8d3599f955668d94ea562a1d0eafd3ac74871b.tar.gz papod-1a8d3599f955668d94ea562a1d0eafd3ac74871b.tar.xz |
src/utils.mjs: Add undefinedAsNull()
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, ]); |