Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

how circular references maybe could work #14

Closed
wants to merge 1 commit into from
Closed
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
50 changes: 50 additions & 0 deletions src/handlers/tsonCircular.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect, test } from "vitest";

import { createTson } from "../tson.js";
import { tsonCircular } from "./index.js";

Check failure on line 7 in src/handlers/tsonCircular.test.ts

View workflow job for this annotation

GitHub Actions / type_check

Module '"./index.js"' has no exported member 'tsonCircular'.

test("circular", () => {
const t = createTson({
types: [tsonCircular],
});

{
const expected: any = {};

expected.a = expected;

expect(t.serialize(expected).json).toBe({
a: [
//
"Circular",
0, // <-- 0 means that the direct parent is circular target
"__tson",
],
});

// const deserialized = t.parse(stringified);
// expect(deserialized).toEqual(expected);
}

{
const expected: any = {
a: {
b: {},
},
};

expected.a.b.a = expected;

expect(t.serialize(expected).json).toBe({
a: [
//
"Circular",
1, // <-- 1 means that the grandparent is circular target
"__tson",
],
});
}
});
Loading