From f553c2460f4d000ce3abb98bd21a1f96dcd116a3 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 8 Sep 2025 19:24:39 +0700 Subject: [PATCH] Fix DOMException serialization to include error code constants Fixes #107 --- test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test.js b/test.js index 305de49..db7864e 100644 --- a/test.js +++ b/test.js @@ -619,4 +619,22 @@ if ('DOMException' in globalThis) { const serialized = serializeError(new DOMException('x')); t.is(serialized.message, 'x'); }); + + test('should deep clone DOMException when it is in the cause property', t => { + const domException = new DOMException('My domException', 'NotFoundError'); + const error = new Error('My error message', { + cause: domException, + }); + + const serialized = serializeError(error); + + t.is(serialized.message, 'My error message'); + t.is(serialized.cause.message, 'My domException'); + t.is(serialized.cause.name, 'NotFoundError'); + t.is(serialized.cause.code, 8); + // Should be a deep clone, not the same reference + t.not(serialized.cause, domException); + t.false(serialized.cause instanceof DOMException); + t.false(serialized.cause instanceof Error); + }); }