aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/util/bun-inspect.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/js/node/util/bun-inspect.test.ts')
-rw-r--r--test/js/node/util/bun-inspect.test.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/js/node/util/bun-inspect.test.ts b/test/js/node/util/bun-inspect.test.ts
new file mode 100644
index 000000000..308f275b9
--- /dev/null
+++ b/test/js/node/util/bun-inspect.test.ts
@@ -0,0 +1,23 @@
+import { describe, it, expect } from "bun:test";
+
+describe("Bun.inspect", () => {
+ it("depth < 0 throws", () => {
+ expect(() => Bun.inspect({}, { depth: -1 })).toThrow();
+ expect(() => Bun.inspect({}, { depth: -13210 })).toThrow();
+ });
+ it("depth = Infinity works", () => {
+ function createRecursiveObject(n: number): any {
+ if (n === 0) return { hi: true };
+ return { a: createRecursiveObject(n - 1) };
+ }
+
+ const obj = createRecursiveObject(1000);
+
+ expect(Bun.inspect(obj, { depth: Infinity })).toContain("hi");
+ // this gets converted to u16, which if just truncating, will turn into 0
+ expect(Bun.inspect(obj, { depth: 0x0fff0000 })).toContain("hi");
+ });
+ it("depth = 0", () => {
+ expect(Bun.inspect({ a: { b: { c: { d: 1 } } } }, { depth: 0 })).toEqual("{\n a: [Object ...]\n}");
+ });
+});