From 5bedad30d38ab401b65a33bf165f5d5aaa644471 Mon Sep 17 00:00:00 2001 From: Bluebberies Date: Thu, 24 Oct 2024 00:25:45 +0100 Subject: [PATCH] Added tests to check for flatten call unhandled error --- test/unhandledExceptionsTest.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/unhandledExceptionsTest.js diff --git a/test/unhandledExceptionsTest.js b/test/unhandledExceptionsTest.js new file mode 100644 index 0000000..cc2cfb8 --- /dev/null +++ b/test/unhandledExceptionsTest.js @@ -0,0 +1,28 @@ +import assert from "node:assert"; +import { describe, test } from "node:test"; +import { flatten, unflatten } from "../index.js"; + +describe("flatten obj tests", function () { + test("Flatten null", function () { + assert.deepStrictEqual(flatten(null), null); + }); + + test("Flatten undefined", function () { + assert.deepStrictEqual(flatten(undefined), undefined); + }); + + test("Flatten object with Symbol keys", function () { + const sym = Symbol("test"); + const obj = { [sym]: "value", regularKey: "regularValue" }; + const flatObj = flatten(obj); + + assert.strictEqual(flatObj["Symbol(test)"], "value"); // Assuming stringification of symbol keys + }); + + test("Flatten circular reference", function () { + const obj = { name: "John" }; + obj.self = obj; // Circular reference + + assert.throws(() => flatten(obj), /Circular reference detected/); + }); +});