summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-12-13 04:05:41 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-12-18 12:34:08 +0100
commit3b2698e41f27a1d0c51833dab32bdaa98e6ef8cb (patch)
treefe05d45f7783ad9b56a8ece0021494138018bf41
parent0858e5d9d8db085cb83b3f1f3f94ed6b550a7bc5 (diff)
downloadandroid-node-v8-3b2698e41f27a1d0c51833dab32bdaa98e6ef8cb.tar.gz
android-node-v8-3b2698e41f27a1d0c51833dab32bdaa98e6ef8cb.tar.bz2
android-node-v8-3b2698e41f27a1d0c51833dab32bdaa98e6ef8cb.zip
assert: inspect getters
While asserting two objects the descriptor is not taken into account. Therefore getters will be triggered as such. This makes sure they are also highlighted in the error message instead of potentially looking identical while the return value of the getter is actually different. PR-URL: https://github.com/nodejs/node/pull/25004 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
-rw-r--r--lib/internal/assert.js4
-rw-r--r--test/parallel/test-assert-deep.js24
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/internal/assert.js b/lib/internal/assert.js
index 829f666319..29769fc561 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 c1e8c2f246..ceb17bdf56 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 });
+}