diff --git a/lib/internal/assert.js b/lib/internal/assert.js index 829f6663191dff..29769fc5617b95 100644 --- a/lib/internal/assert.js +++ b/lib/internal/assert.js @@ -56,7 +56,9 @@ function inspectValue(val) { breakLength: Infinity, // Assert does not detect proxies currently. showProxy: false, - sorted: true + sorted: true, + // Inspect getters as we also check them when comparing entries. + getters: true } ); } diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index c1e8c2f246663b..ceb17bdf56364d 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -24,7 +24,8 @@ function re(literals, ...values) { customInspect: false, maxArrayLength: Infinity, breakLength: Infinity, - sorted: true + sorted: true, + getters: true }); // Need to escape special characters. result += str; @@ -1049,3 +1050,24 @@ assert.throws( }); assertDeepAndStrictEqual(a, b); } + +// Check getters. +{ + const a = { + get a() { return 5; } + }; + const b = { + get a() { return 6; } + }; + assert.throws( + () => assert.deepStrictEqual(a, b), + { + code: 'ERR_ASSERTION', + name: 'AssertionError [ERR_ASSERTION]', + message: /a: \[Getter: 5]\n- a: \[Getter: 6]\n / + } + ); + + // The descriptor is not compared. + assertDeepAndStrictEqual(a, { a: 5 }); +}