summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-05-05 15:54:39 +0100
committerLinus Groh <mail@linusgroh.de>2021-05-05 15:58:53 +0100
commit346560d7c8df3404b8bae89d95b32b377e3ad783 (patch)
tree7fe045ebe0dde553b670489449a827a270157752 /Userland
parentd9702ff5617f1646a36dc97ffa51459d31e1df7d (diff)
downloadserenity-346560d7c8df3404b8bae89d95b32b377e3ad783.zip
LibJS/Tests: Use hasOwnProperty() for duplicate test check
The current way of doing this would also traverse the prototype chain, and therefore yield false positive results for keys like "toString".
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js3
-rw-r--r--Userland/Libraries/LibJS/Tests/test-common.js10
2 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js b/Userland/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js
index a8afde0ea3..7121d6c18d 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Array/Array.prototype-generic-functions.js
@@ -53,8 +53,7 @@ describe("ability to work with generic non-array objects", () => {
);
});
- // FIXME: test-js asserts when this is just called "toString" ಠ_ಠ
- test("toString (FIXME)", () => {
+ test("toString", () => {
expect(Array.prototype.toString.call({})).toBe("[object Object]");
expect(Array.prototype.toString.call({ join: "foo" })).toBe("[object Object]");
expect(Array.prototype.toString.call({ join: () => "foo" })).toBe("foo");
diff --git a/Userland/Libraries/LibJS/Tests/test-common.js b/Userland/Libraries/LibJS/Tests/test-common.js
index 9cec16a2e6..271dcd4363 100644
--- a/Userland/Libraries/LibJS/Tests/test-common.js
+++ b/Userland/Libraries/LibJS/Tests/test-common.js
@@ -431,7 +431,7 @@ class ExpectationError extends Error {
if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {};
const suite = __TestResults__[suiteMessage];
- if (suite[message]) {
+ if (Object.prototype.hasOwnProperty.call(suite, message)) {
suite[message] = {
result: "fail",
details: "Another test with the same message did already run",
@@ -459,7 +459,13 @@ class ExpectationError extends Error {
if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {};
const suite = __TestResults__[suiteMessage];
- if (suite[message]) throw new Error("Duplicate test name: " + message);
+ if (Object.prototype.hasOwnProperty.call(suite, message)) {
+ suite[message] = {
+ result: "fail",
+ details: "Another test with the same message did already run",
+ };
+ return;
+ }
suite[message] = {
result: "skip",