Files
discordeno/tests/util/loop_object.ts
2021-05-03 18:52:57 +00:00

58 lines
1.0 KiB
TypeScript

import { loopObject } from "../../src/util/loop_object.ts";
import { assertEquals } from "../deps.ts";
const objWithBigints = {
a: BigInt(0),
b: "string",
c: 123,
d: [123],
e: {
f: 123,
g: BigInt(2),
},
h: null,
i: undefined,
j: 0,
// k: function () {
// return true;
// },
};
const correctlyConverted = {
a: "0",
b: "string",
c: 123,
d: [123],
e: {
f: 123,
g: "2",
},
h: null,
i: undefined,
j: 0,
// k: function () {
// return true;
// },
};
Deno.test({
name: "[utils] loop over an object with a handler",
fn() {
const converted = loopObject(
objWithBigints,
(value) =>
typeof value === "bigint"
? value.toString()
: Array.isArray(value)
? value.map((v) => typeof v === "bigint" ? v.toString() : v)
: value,
`Running for loop in unit test function for changing bigints to strings.`,
);
assertEquals(
converted,
correctlyConverted,
);
},
});