Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests to check for flatten call with null, undefined, symbol keys and circular references #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/unhandledExceptionsTest.js
Original file line number Diff line number Diff line change
@@ -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/);
});
});