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

assert: inspect getters #25004

Closed
Closed
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion lib/internal/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
);
}
Expand Down
24 changes: 23 additions & 1 deletion test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 });
}