trim-obj
Version:
Recursively trim object values
64 lines (63 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const trim_obj_1 = require("./trim-obj");
describe("trimObj", () => {
it("recursively trim object values", () => {
class Person {
constructor(msg) {
this.msg = msg;
}
speak() {
console.log(this.msg);
}
}
const input = {
foo: "bar ",
bar: " baz",
baz: " qUx ",
quux: {
quuz: " CORGE",
grault: " garply ",
waldo: {
fred: " plugh",
xyzzy: "thud",
},
},
Wibble: ["wobble", " wubble ", " flob "],
toto: ["wolf ", " tata", { titi: " tutu " }],
hoge: 1,
piyo: [],
hogera: {
fuga: false,
hogehoge: new Date("2021-11-01"),
},
wobble: new Error(" Wibble "),
fuga: new Person(" speech "),
};
const output = (0, trim_obj_1.trimObj)(input);
expect(output).toEqual({
foo: "bar",
bar: "baz",
baz: "qUx",
quux: {
quuz: "CORGE",
grault: "garply",
waldo: {
fred: "plugh",
xyzzy: "thud",
},
},
Wibble: ["wobble", "wubble", "flob"],
toto: ["wolf", "tata", { titi: "tutu" }],
hoge: 1,
piyo: [],
hogera: {
fuga: false,
hogehoge: new Date("2021-11-01"),
},
wobble: new Error(" Wibble "),
fuga: new Person("speech"),
});
expect(output).not.toBe(input);
});
});