summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2020-07-04 10:09:48 -0700
committerAndreas Kling <kling@serenityos.org>2020-07-06 23:40:35 +0200
commit3f97d75778998b160372e895ccaba03cf09ad4aa (patch)
tree86cd641a274155a7f7a9728b0c7612b7bd663a59
parent46581773c104a6739c423968c65cf8fbcc7e5e6f (diff)
downloadserenity-3f97d75778998b160372e895ccaba03cf09ad4aa.zip
LibJS: Convert most builtin tests to new system
-rw-r--r--Libraries/LibJS/Tests/builtins/Boolean/Boolean.js66
-rw-r--r--Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js15
-rw-r--r--Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js30
-rw-r--r--Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js29
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.now.js15
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js18
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js15
-rw-r--r--Libraries/LibJS/Tests/builtins/Error/Error.js51
-rw-r--r--Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js18
-rw-r--r--Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js20
-rw-r--r--Libraries/LibJS/Tests/builtins/Function/Function.js76
-rw-r--r--Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js44
-rw-r--r--Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js194
-rw-r--r--Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js46
-rw-r--r--Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js24
-rw-r--r--Libraries/LibJS/Tests/builtins/Infinity/Infinity-basic.js27
-rw-r--r--Libraries/LibJS/Tests/builtins/Infinity/Infinity.js22
-rw-r--r--Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js14
-rw-r--r--Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js30
-rw-r--r--Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js14
-rw-r--r--Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js14
-rw-r--r--Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js14
-rw-r--r--Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js124
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math-constants.js26
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.abs.js28
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.acosh.js20
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.asinh.js15
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.atanh.js22
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js26
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.ceil.js32
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.clz32.js90
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.cos.js30
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.exp.js32
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.expm1.js32
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.floor.js32
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.log1p.js19
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.max.js23
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.min.js21
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.pow.js52
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.sign.js56
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.sin.js32
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js11
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.tan.js30
-rw-r--r--Libraries/LibJS/Tests/builtins/Math/Math.trunc.js30
-rw-r--r--Libraries/LibJS/Tests/builtins/NaN/NaN-basic.js21
-rw-r--r--Libraries/LibJS/Tests/builtins/NaN/NaN.js13
-rw-r--r--Libraries/LibJS/Tests/builtins/Number/Number-constants.js28
-rw-r--r--Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js50
-rw-r--r--Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js64
-rw-r--r--Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js52
-rw-r--r--Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js50
-rw-r--r--Libraries/LibJS/Tests/builtins/Number/Number.js68
-rw-r--r--Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js12
-rw-r--r--Libraries/LibJS/Tests/builtins/Number/Number.prototype.js14
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js214
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.entries.js81
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js86
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js26
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js19
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.is.js99
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js28
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.js20
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.keys.js70
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js91
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js46
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js24
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.prototype.js11
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js49
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js16
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js63
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.values.js70
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js38
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.js32
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js31
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js36
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js37
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js28
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js14
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.js20
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js47
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js38
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js38
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js52
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js36
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js72
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js31
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js20
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js15
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js20
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js114
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js12
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.raw.js34
-rw-r--r--Libraries/LibJS/Tests/builtins/functions/isFinite.js48
-rw-r--r--Libraries/LibJS/Tests/builtins/functions/isNaN.js46
-rw-r--r--Libraries/LibJS/Tests/builtins/functions/parseFloat.js66
-rw-r--r--Libraries/LibJS/Tests/test-common-tests.js108
-rw-r--r--Libraries/LibJS/Tests/test-common.js50
-rw-r--r--Userland/test-js.cpp111
107 files changed, 2045 insertions, 2257 deletions
diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js
index 9f9758ced2..c7415afe1a 100644
--- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js
+++ b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.js
@@ -1,40 +1,32 @@
-load("test-common.js");
-
-try {
- assert(Boolean.length === 1);
- assert(Boolean.name === "Boolean");
- assert(Boolean.prototype.length === undefined);
-
- assert(typeof new Boolean() === "object");
- assert(new Boolean().valueOf() === false);
-
+test("constructor properties", () => {
+ expect(Boolean).toHaveLength(1);
+ expect(Boolean.name).toBe("Boolean");
+});
+
+test("typeof", () => {
+ expect(typeof new Boolean()).toBe("object");
+ expect(typeof Boolean()).toBe("boolean");
+ expect(typeof Boolean(true)).toBe("boolean");
+})
+
+test("basic functionality", () => {
var foo = new Boolean(true);
var bar = new Boolean(true);
- assert(foo !== bar);
- assert(foo.valueOf() === bar.valueOf());
-
- assert(new Boolean(true).toString() === "true");
- assert(new Boolean(false).toString() === "false");
-
- assert(typeof Boolean() === "boolean");
- assert(typeof Boolean(true) === "boolean");
-
- assert(Boolean() === false);
- assert(Boolean(false) === false);
- assert(Boolean(null) === false);
- assert(Boolean(undefined) === false);
- assert(Boolean(NaN) === false);
- assert(Boolean("") === false);
- assert(Boolean(0.0) === false);
- assert(Boolean(-0.0) === false);
- assert(Boolean(true) === true);
- assert(Boolean("0") === true);
- assert(Boolean({}) === true);
- assert(Boolean([]) === true);
- assert(Boolean(1)) === true;
-
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+ expect(foo).not.toBe(bar);
+ expect(foo.valueOf()).toBe(bar.valueOf());
+
+ expect(Boolean()).toBeFalse();
+ expect(Boolean(false)).toBeFalse();
+ expect(Boolean(null)).toBeFalse();
+ expect(Boolean(undefined)).toBeFalse();
+ expect(Boolean(NaN)).toBeFalse();
+ expect(Boolean("")).toBeFalse();
+ expect(Boolean(0.0)).toBeFalse();
+ expect(Boolean(-0.0)).toBeFalse();
+ expect(Boolean(true)).toBeTrue();
+ expect(Boolean("0")).toBeTrue();
+ expect(Boolean({})).toBeTrue();
+ expect(Boolean([])).toBeTrue();
+ expect(Boolean(1)).toBeTrue();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js
index 31cb114a82..ba06a1a423 100644
--- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js
+++ b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.js
@@ -1,10 +1,5 @@
-load("test-common.js");
-
-try {
- assert(typeof Boolean.prototype === "object");
- assert(Boolean.prototype.valueOf() === false);
-
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+test("basic functionality", () => {
+ expect(typeof Boolean.prototype).toBe("object");
+ expect(Boolean.prototype.valueOf()).toBeFalse();
+ expect(Boolean.prototype.length).toBeUndefined();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js
index a2130b9622..506b23feac 100644
--- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js
+++ b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.toString.js
@@ -1,21 +1,17 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var foo = true;
- assert(foo.toString() === "true");
- assert(true.toString() === "true");
+ expect(foo.toString()).toBe("true");
+ expect(true.toString()).toBe("true");
- assert(Boolean.prototype.toString.call(true) === "true");
- assert(Boolean.prototype.toString.call(false) === "false");
+ expect(Boolean.prototype.toString.call(true)).toBe("true");
+ expect(Boolean.prototype.toString.call(false)).toBe("false");
- assertThrowsError(() => {
- Boolean.prototype.toString.call("foo");
- }, {
- error: TypeError,
- message: "Not a Boolean object"
- });
+ expect(new Boolean(true).toString()).toBe("true");
+ expect(new Boolean(false).toString()).toBe("false");
+});
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+test("errors on non-boolean |this|", () => {
+ expect(() => {
+ Boolean.prototype.toString.call("foo");
+ }).toThrowWithMessage(TypeError, "Not a Boolean object");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js
index 85021d3543..d510523c5b 100644
--- a/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js
+++ b/Libraries/LibJS/Tests/builtins/Boolean/Boolean.prototype.valueOf.js
@@ -1,21 +1,16 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var foo = true;
- assert(foo.valueOf() === true);
- assert(true.valueOf() === true);
+ expect(foo.valueOf()).toBeTrue();
+ expect(true.valueOf()).toBeTrue();
- assert(Boolean.prototype.valueOf.call(true) === true);
- assert(Boolean.prototype.valueOf.call(false) === false);
+ expect(Boolean.prototype.valueOf.call(true)).toBeTrue();
+ expect(Boolean.prototype.valueOf.call(false)).toBeFalse();
- assertThrowsError(() => {
- Boolean.prototype.valueOf.call("foo");
- }, {
- error: TypeError,
- message: "Not a Boolean object"
- });
+ expect(new Boolean().valueOf()).toBeFalse();
+});
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+test("errors on non-boolean |this|", () => {
+ expect(() => {
+ Boolean.prototype.valueOf.call("foo");
+ }).toThrowWithMessage(TypeError, "Not a Boolean object");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.js b/Libraries/LibJS/Tests/builtins/Date/Date.js
index 383864d604..3934fb5142 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.js
@@ -1,11 +1,5 @@
-load("test-common.js");
-
-try {
- assert(Date.length === 7);
- assert(Date.name === "Date");
- assert(Date.prototype.length === undefined);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Date).toHaveLength(7);
+ expect(Date.name === "Date");
+ expect(Date.prototype).not.toHaveProperty("length");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.now.js b/Libraries/LibJS/Tests/builtins/Date/Date.now.js
index 72c5cc7930..46c1b6d8cd 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.now.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.now.js
@@ -1,15 +1,10 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var last = 0;
for (var i = 0; i < 100; ++i) {
var now = Date.now();
- assert(!isNaN(now))
- assert(now > 1580000000000);
- assert(now >= last);
+ expect(now).not.toBeNaN();
+ expect(now).toBeGreaterThan(1580000000000);
+ expect(now).toBeGreaterThanOrEqual(last);
last = now;
}
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js
index 4ad6a3b390..647e43a997 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDate.js
@@ -1,11 +1,7 @@
-load("test-common.js");
-
-try {
- var d = new Date();
- assert(!isNaN(d.getDate()));
- assert(1 <= d.getDate() <= 31);
- assert(d.getDate() === d.getDate());
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ let d = new Date();
+ expect(d.getDate()).toBe(d.getDate());
+ expect(d.getDate()).not.toBeNaN();
+ expect(d.getDate()).toBeGreaterThanOrEqual(1);
+ expect(d.getDate()).toBeLessThanOrEqual(31);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js
index 94dbe1622b..534efeeee5 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getDay.js
@@ -1,11 +1,7 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var d = new Date();
- assert(!isNaN(d.getDay()));
- assert(0 <= d.getDay() <= 6);
- assert(d.getDay() === d.getDay());
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(d.getDay()).toBe(d.getDay());
+ expect(d.getDay()).not.toBeNaN();
+ expect(d.getDay()).toBeGreaterThanOrEqual(0);
+ expect(d.getDay()).toBeLessThanOrEqual(6);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js
index 44416882c9..3748e835cf 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getFullYear.js
@@ -1,11 +1,7 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var d = new Date();
- assert(!isNaN(d.getFullYear()));
- assert(d.getFullYear() >= 2020);
- assert(d.getFullYear() === d.getFullYear());
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(d.getFullYear()).toBe(d.getFullYear());
+ expect(d.getFullYear()).not.toBeNaN();
+ expect(d.getFullYear()).toBe(d.getFullYear());
+ expect(d.getFullYear()).toBeGreaterThanOrEqual(2020);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js
index 2e7984b497..7e562288f2 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getHours.js
@@ -1,11 +1,7 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var d = new Date();
- assert(!isNaN(d.getHours()));
- assert(0 <= d.getHours() <= 23);
- assert(d.getHours() === d.getHours());
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(d.getHours()).toBe(d.getHours());
+ expect(d.getHours()).not.toBeNaN();
+ expect(d.getHours()).toBeGreaterThanOrEqual(0);
+ expect(d.getHours()).toBeLessThanOrEqual(23);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js
index 49ef970fe8..90c686f729 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMilliseconds.js
@@ -1,11 +1,7 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var d = new Date();
- assert(!isNaN(d.getMilliseconds()));
- assert(0 <= d.getMilliseconds() <= 999);
- assert(d.getMilliseconds() === d.getMilliseconds());
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(d.getMilliseconds()).toBe(d.getMilliseconds());
+ expect(d.getMilliseconds()).not.toBeNaN();
+ expect(d.getMilliseconds()).toBeGreaterThanOrEqual(0);
+ expect(d.getMilliseconds()).toBeLessThanOrEqual(999);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js
index 380f864ed4..5b87b8251d 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMinutes.js
@@ -1,11 +1,7 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var d = new Date();
- assert(!isNaN(d.getMinutes()));
- assert(0 <= d.getMinutes() <= 59);
- assert(d.getMinutes() === d.getMinutes());
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(d.getMinutes()).toBe(d.getMinutes());
+ expect(d.getMinutes()).not.toBeNaN();
+ expect(d.getMinutes()).toBeGreaterThanOrEqual(0);
+ expect(d.getMinutes()).toBeLessThanOrEqual(59);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js
index 3556770058..7d52866ce7 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getMonth.js
@@ -1,11 +1,7 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var d = new Date();
- assert(!isNaN(d.getMonth()));
- assert(0 <= d.getMonth() <= 11);
- assert(d.getMonth() === d.getMonth());
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(d.getMonth()).toBe(d.getMonth());
+ expect(d.getMonth()).not.toBeNaN();
+ expect(d.getMonth()).toBeGreaterThanOrEqual(0);
+ expect(d.getMonth()).toBeLessThanOrEqual(11);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js
index 7247bc9f13..df30881c9a 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getSeconds.js
@@ -1,11 +1,7 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var d = new Date();
- assert(!isNaN(d.getSeconds()));
- assert(0 <= d.getSeconds() <= 59);
- assert(d.getSeconds() === d.getSeconds());
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(d.getSeconds()).toBe(d.getSeconds());
+ expect(d.getSeconds()).not.toBeNaN();
+ expect(d.getSeconds()).toBeGreaterThanOrEqual(0);
+ expect(d.getSeconds()).toBeLessThanOrEqual(59);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js
index 8c352465fe..b9ada6fcc9 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.getTime.js
@@ -1,11 +1,6 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var d = new Date();
- assert(!isNaN(d.getTime()));
- assert(d.getTime() > 1580000000000);
- assert(d.getTime() === d.getTime());
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(d.getTime()).toBe(d.getTime());
+ expect(d.getTime()).not.toBeNaN();
+ expect(d.getTime()).toBeGreaterThanOrEqual(1580000000000);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Error/Error.js b/Libraries/LibJS/Tests/builtins/Error/Error.js
index ed920cb9ba..a452bd7a88 100644
--- a/Libraries/LibJS/Tests/builtins/Error/Error.js
+++ b/Libraries/LibJS/Tests/builtins/Error/Error.js
@@ -1,33 +1,18 @@
-load("test-common.js");
-
-try {
- assert(Error.length === 1);
- assert(Error.name === "Error");
- assert(Error.prototype.length === undefined);
-
- var e;
-
- e = Error();
- assert(e.name === "Error");
- assert(e.message === "");
-
- e = Error(undefined);
- assert(e.name === "Error");
- assert(e.message === "");
-
- e = Error("test");
- assert(e.name === "Error");
- assert(e.message === "test");
-
- e = Error(42);
- assert(e.name === "Error");
- assert(e.message === "42");
-
- e = Error(null);
- assert(e.name === "Error");
- assert(e.message === "null");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Error).toHaveLength(1);
+ expect(Error.name).toBe("Error");
+});
+
+test("name", () => {
+ [Error(), Error(undefined), Error("test"), Error(42), Error(null)].forEach(error => {
+ expect(error.name).toBe("Error");
+ });
+});
+
+test("message", () => {
+ expect(Error().message).toBe("");
+ expect(Error(undefined).message).toBe("");
+ expect(Error("test").message).toBe("test");
+ expect(Error(42).message).toBe("42");
+ expect(Error(null).message).toBe("null");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js
index 48123543df..9e64eda1a3 100644
--- a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js
+++ b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.name.js
@@ -1,14 +1,10 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
+ expect(Error.prototype).not.toHaveProperty("length");
+
var changedInstance = new Error("");
- changedInstance.name = 'NewCustomError';
- assert(changedInstance.name === "NewCustomError");
+ changedInstance.name = "NewCustomError";
+ expect(changedInstance.name).toBe("NewCustomError");
var normalInstance = new Error("");
- assert(normalInstance.name === "Error");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e.message);
-}
+ expect(normalInstance.name).toBe("Error");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js
index e4f1d7db1e..b5d2f7dceb 100644
--- a/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js
+++ b/Libraries/LibJS/Tests/builtins/Error/Error.prototype.toString.js
@@ -1,13 +1,7 @@
-load("test-common.js");
-
-try {
- assert(Error().toString() === "Error");
- assert(Error(undefined).toString() === "Error");
- assert(Error(null).toString() === "Error: null");
- assert(Error("test").toString() === "Error: test");
- assert(Error(42).toString() === "Error: 42");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Error().toString()).toBe("Error");
+ expect(Error(undefined).toString()).toBe("Error");
+ expect(Error(null).toString()).toBe("Error: null");
+ expect(Error("test").toString()).toBe("Error: test");
+ expect(Error(42).toString()).toBe("Error: 42");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.js b/Libraries/LibJS/Tests/builtins/Function/Function.js
index 52f07c103b..e56b5e4738 100644
--- a/Libraries/LibJS/Tests/builtins/Function/Function.js
+++ b/Libraries/LibJS/Tests/builtins/Function/Function.js
@@ -1,42 +1,44 @@
-load("test-common.js");
-
-try {
- assert(Function.length === 1);
- assert(Function.name === "Function");
- assert(Function.prototype.length === 0);
- assert(Function.prototype.name === "");
-
- assert(typeof Function() === "function");
- assert(typeof new Function() === "function");
+describe("correct behavior", () => {
+ test("constructor properties", () => {
+ expect(Function).toHaveLength(1);
+ expect(Function.name).toBe("Function");
+ expect(Function.prototype).toHaveLength(0);
+ expect(Function.prototype.name).toBe("");
+ });
- assert(Function()() === undefined);
- assert(new Function()() === undefined);
- assert(Function("return 42")() === 42);
- assert(new Function("return 42")() === 42);
- assert(new Function("foo", "return foo")(42) === 42);
- assert(new Function("foo,bar", "return foo + bar")(1, 2) === 3);
- assert(new Function("foo", "bar", "return foo + bar")(1, 2) === 3);
- assert(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3) === 6);
- assert(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3) === 6);
- assert(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true) === 42);
- assert(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false) === "bar");
- assert(new Function("return typeof Function()")() === "function");
- assert(new Function("x", "return function (y) { return x + y };")(1)(2) === 3);
+ test("typeof", () => {
+ expect(typeof Function()).toBe("function");
+ expect(typeof new Function()).toBe("function");
+ });
- assert(new Function().name === "anonymous");
- assert(new Function().toString() === "function anonymous() {\n ???\n}");
+ test("basic functionality", () => {
+ expect(Function()()).toBe(undefined);
+ expect(new Function()()).toBe(undefined);
+ expect(Function("return 42")()).toBe(42);
+ expect(new Function("return 42")()).toBe(42);
+ expect(new Function("foo", "return foo")(42)).toBe(42);
+ expect(new Function("foo,bar", "return foo + bar")(1, 2)).toBe(3);
+ expect(new Function("foo", "bar", "return foo + bar")(1, 2)).toBe(3);
+ expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
+ expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
+ expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe(42);
+ expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe("bar");
+ expect(new Function("return typeof Function()")()).toBe("function");
+ expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3);
- assertThrowsError(() => {
- new Function("[");
- }, {
- error: SyntaxError,
- // This might be confusing at first but keep in mind it's actually parsing
- // function anonymous() { [ }
- // This is in line with what other engines are reporting.
- message: "Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"
+ expect(new Function().name).toBe("anonymous");
+ expect(new Function().toString()).toBe("function anonymous() {\n ???\n}");
});
+});
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e.message);
-}
+describe("errors", () => {
+ test("syntax error", () => {
+ expect(() => {
+ new Function("[");
+ })
+ // This might be confusing at first but keep in mind it's actually parsing
+ // function anonymous() { [ }
+ // This is in line with what other engines are reporting.
+ .toThrowWithMessage(SyntaxError, "Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)");
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js
index 54451e3446..c13ec7e7e7 100644
--- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js
+++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.apply.js
@@ -1,6 +1,4 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
function Foo(arg) {
this.foo = arg;
}
@@ -17,39 +15,35 @@ try {
this.baz = arg;
}
- assert(Function.prototype.apply.length === 2);
+ expect(Function.prototype.apply).toHaveLength(2);
var foo = new Foo("test");
- assert(foo.foo === "test");
- assert(foo.bar === undefined);
- assert(foo.baz === undefined);
+ expect(foo.foo).toBe("test");
+ expect(foo.bar).toBeUndefined();
+ expect(foo.baz).toBeUndefined();
var bar = new Bar("test");
- assert(bar.foo === undefined);
- assert(bar.bar === "test");
- assert(bar.baz === undefined);
+ expect(bar.foo).toBeUndefined();
+ expect(bar.bar).toBe("test");
+ expect(bar.baz).toBeUndefined();
var foobar = new FooBar("test");
- assert(foobar.foo === "test");
- assert(foobar.bar === "test");
- assert(foobar.baz === undefined);
+ expect(foobar.foo).toBe("test");
+ expect(foobar.bar).toBe("test");
+ expect(foobar.baz).toBeUndefined();
var foobarbaz = new FooBarBaz("test");
- assert(foobarbaz.foo === "test");
- assert(foobarbaz.bar === "test");
- assert(foobarbaz.baz === "test");
+ expect(foobarbaz.foo).toBe("test");
+ expect(foobarbaz.bar).toBe("test");
+ expect(foobarbaz.baz).toBe("test");
- assert(Math.abs.apply(null, [-1]) === 1);
+ expect(Math.abs.apply(null, [-1])).toBe(1);
var add = (x, y) => x + y;
- assert(add.apply(null, [1, 2]) === 3);
+ expect(add.apply(null, [1, 2])).toBe(3);
var multiply = function (x, y) { return x * y; };
- assert(multiply.apply(null, [3, 4]) === 12);
-
- assert((() => this).apply("foo") === globalThis);
+ expect(multiply.apply(null, [3, 4])).toBe(12);
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect((() => this).apply("foo")).toBe(globalThis);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js
index 7f2801fb14..fd3d9abaf6 100644
--- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js
+++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.bind.js
@@ -1,124 +1,138 @@
-load("test-common.js");
+describe("basic behavior", () => {
+ test("basic binding", () => {
+ expect(Function.prototype.bind.length).toBe(1);
-try {
- assert(Function.prototype.bind.length === 1);
+ var charAt = String.prototype.charAt.bind("bar");
+ expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar");
- var charAt = String.prototype.charAt.bind("bar");
- assert(charAt(0) + charAt(1) + charAt(2) === "bar");
-
- function getB() {
- return this.toUpperCase().charAt(0);
- }
- assert(getB.bind("bar")() === "B");
-
- // Bound functions should work with array functions
- var Make3 = Number.bind(null, 3);
- assert([55].map(Make3)[0] === 3);
+ function getB() {
+ return this.toUpperCase().charAt(0);
+ }
+ expect(getB.bind("bar")()).toBe("B");
+ });
- var MakeTrue = Boolean.bind(null, true);
- assert([1, 2, 3].filter(MakeTrue).length === 3);
+ test("bound functions work with array functions", () => {
+ var Make3 = Number.bind(null, 3);
+ expect([55].map(Make3)[0]).toBe(3);
- assert([1, 2, 3].reduce((function (acc, x) { return acc + x }).bind(null, 4, 5)) === 9);
+ var MakeTrue = Boolean.bind(null, true);
- assert([1, 2, 3].reduce((function (acc, x) { return acc + x + this; }).bind(3)) === 12);
+ expect([1, 2, 3].filter(MakeTrue).length).toBe(3);
+ expect([1, 2, 3].reduce((function (acc, x) { return acc + x }).bind(null, 4, 5))).toBe(9);
+ expect([1, 2, 3].reduce((function (acc, x) { return acc + x + this; }).bind(3))).toBe(12);
+ });
+});
+describe("bound function arguments", () => {
function sum(a, b, c) {
return a + b + c;
}
-
- // Arguments should be able to be bound to a function.
var boundSum = sum.bind(null, 10, 5);
- assert(isNaN(boundSum()));
- assert(boundSum(5) === 20);
- assert(boundSum(5, 6, 7) === 20);
+ test("arguments are bound to the function", () => {
+ expect(boundSum()).toBeNaN();
+ expect(boundSum(5)).toBe(20);
+ expect(boundSum(5, 6, 7)).toBe(20);
+ });
+
+ test("arguments are appended to a BoundFunction's bound arguments", () => {
+ expect(boundSum.bind(null, 5)()).toBe(20);
+ });
- // Arguments should be appended to a BoundFunction's bound arguments.
- assert(boundSum.bind(null, 5)() === 20);
+ test("binding a constructor's arguments", () => {
+ var Make5 = Number.bind(null, 5);
+ expect(Make5()).toBe(5);
+ expect(new Make5().valueOf()).toBe(5);
+ });
- // A BoundFunction's length property should be adjusted based on the number
- // of bound arguments.
- assert(sum.length === 3);
- assert(boundSum.length === 1);
- assert(boundSum.bind(null, 5).length === 0);
- assert(boundSum.bind(null, 5, 6, 7, 8).length === 0);
+ test("length property", () => {
+ expect(sum).toHaveLength(3);
+ expect(boundSum).toHaveLength(1);
+ expect(boundSum.bind(null, 5)).toHaveLength(0);
+ expect(boundSum.bind(null, 5, 6, 7, 8)).toHaveLength(0);
+ });
+})
+describe("bound function |this|", () => {
function identity() {
return this;
}
- // It should capture the global object if the |this| value is null or undefined.
- assert(identity.bind()() === globalThis);
- assert(identity.bind(null)() === globalThis);
- assert(identity.bind(undefined)() === globalThis);
+ test("captures global object as |this| if |this| is null or undefined", () => {
+ expect(identity.bind()()).toBe(globalThis);
+ expect(identity.bind(null)()).toBe(globalThis);
+ expect(identity.bind(undefined)()).toBe(globalThis);
- function Foo() {
- assert(identity.bind()() === globalThis);
- assert(identity.bind(this)() === this);
- }
- new Foo();
+ function Foo() {
+ expect(identity.bind()()).toBe(globalThis);
+ expect(identity.bind(this)()).toBe(this);
+ }
+ new Foo();
+ });
- // Primitive |this| values should be converted to objects.
- assert(identity.bind("foo")() instanceof String);
- assert(identity.bind(123)() instanceof Number);
- assert(identity.bind(true)() instanceof Boolean);
+ test("does not capture global object as |this| if |this| is null or undefined in strict mode", () => {
+ "use strict";
- // It should retain |this| values passed to it.
- var obj = { foo: "bar" };
+ function strictIdentity() {
+ return this;
+ }
- assert(identity.bind(obj)() === obj);
+ expect(strictIdentity.bind()()).toBeUndefined();
+ expect(strictIdentity.bind(null)()).toBeNull();
+ expect(strictIdentity.bind(undefined)()).toBeUndefined();
+ });
- // The bound |this| can not be changed once set
- assert(identity.bind("foo").bind(123)() instanceof String);
+ test("primitive |this| values are converted to objects", () => {
+ expect(identity.bind("foo")()).toBeInstanceOf(String);
+ expect(identity.bind(123)()).toBeInstanceOf(Number);
+ expect(identity.bind(true)()).toBeInstanceOf(Boolean);
+ });
- // The bound |this| value should have no effect on a constructor.
+ test("bound functions retain |this| values passed to them", () => {
+ var obj = { foo: "bar" };
+ expect(identity.bind(obj)()).toBe(obj);
+ });
+
+ test("bound |this| cannot be changed after being set", () => {
+ expect(identity.bind("foo").bind(123)()).toBeInstanceOf(String);
+ });
+
+ test("arrow functions cannot be bound", () => {
+ expect((() => this).bind("foo")()).toBe(globalThis)
+ });
+})
+
+describe("bound function constructors", () => {
function Bar() {
this.x = 3;
this.y = 4;
}
- Bar.prototype.baz = "baz";
+ Bar.prototype.baz = "baz";
var BoundBar = Bar.bind({ u: 5, v: 6 });
-
var bar = new BoundBar();
- assert(bar.x === 3);
- assert(bar.y === 4);
- assert(typeof bar.u === "undefined");
- assert(typeof bar.v === "undefined");
- // Objects constructed from BoundFunctions should retain the prototype of the original function.
- assert(bar.baz === "baz");
- // BoundFunctions should not have a prototype property.
- assert(typeof BoundBar.prototype === "undefined");
-
- // Function.prototype.bind should not accept non-function values.
- assertThrowsError(() => {
- Function.prototype.bind.call("foo");
- }, {
- error: TypeError,
- message: "Not a Function object"
- });
-
- // A constructor's arguments should be able to be bound.
- var Make5 = Number.bind(null, 5);
- assert(Make5() === 5);
- assert(new Make5().valueOf() === 5);
-
- // Null or undefined should be passed through as a |this| value in strict mode.
- (() => {
- "use strict";
- function strictIdentity() {
- return this;
- }
- assert(strictIdentity.bind()() === undefined);
- assert(strictIdentity.bind(null)() === null);
- assert(strictIdentity.bind(undefined)() === undefined);
- })();
- // Arrow functions can not have their |this| value set.
- assert((() => this).bind("foo")() === globalThis)
+ test("bound |this| value does not affect constructor", () => {
+ expect(bar.x).toBe(3);
+ expect(bar.y).toBe(4);
+ expect(typeof bar.u).toBe("undefined");
+ expect(typeof bar.v).toBe("undefined");
+ });
+
+ test("bound functions retain original prototype", () => {
+ expect(bar.baz).toBe("baz");
+ });
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ test("bound functions do not have a prototype property", () => {
+ expect(BoundBar).not.toHaveProperty("prototype");
+ });
+});
+
+describe("errors", () => {
+ test("does not accept non-function values", () => {
+ expect(() => {
+ Function.prototype.bind.call("foo");
+ }).toThrowWithMessage(TypeError, "Not a Function object");
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js
index 485e4645c2..b36195592c 100644
--- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js
+++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.call.js
@@ -1,6 +1,8 @@
-load("test-common.js");
+test("length", () => {
+ expect(Function.prototype.call).toHaveLength(1);
+});
-try {
+test("basic functionality", () => {
function Foo(arg) {
this.foo = arg;
}
@@ -17,39 +19,33 @@ try {
this.baz = arg;
}
- assert(Function.prototype.call.length === 1);
-
var foo = new Foo("test");
- assert(foo.foo === "test");
- assert(foo.bar === undefined);
- assert(foo.baz === undefined);
+ expect(foo.foo).toBe("test");
+ expect(foo.bar).toBeUndefined();
+ expect(foo.baz).toBeUndefined();
var bar = new Bar("test");
- assert(bar.foo === undefined);
- assert(bar.bar === "test");
- assert(bar.baz === undefined);
+ expect(bar.foo).toBeUndefined();
+ expect(bar.bar).toBe("test");
+ expect(bar.baz).toBeUndefined();
var foobar = new FooBar("test");
- assert(foobar.foo === "test");
- assert(foobar.bar === "test");
- assert(foobar.baz === undefined);
+ expect(foobar.foo).toBe("test");
+ expect(foobar.bar).toBe("test");
+ expect(foobar.baz).toBeUndefined();
var foobarbaz = new FooBarBaz("test");
- assert(foobarbaz.foo === "test");
- assert(foobarbaz.bar === "test");
- assert(foobarbaz.baz === "test");
+ expect(foobarbaz.foo).toBe("test");
+ expect(foobarbaz.bar).toBe("test");
+ expect(foobarbaz.baz).toBe("test");
- assert(Math.abs.call(null, -1) === 1);
+ expect(Math.abs.call(null, -1)).toBe(1);
var add = (x, y) => x + y;
- assert(add.call(null, 1, 2) === 3);
+ expect(add.call(null, 1, 2)).toBe(3);
var multiply = function (x, y) { return x * y; };
- assert(multiply.call(null, 3, 4) === 12);
-
- assert((() => this).call("foo") === globalThis);
+ expect(multiply.call(null, 3, 4)).toBe(12);
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect((() => this).call("foo")).toBe(globalThis);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js
index 4f2e1cf5e6..4ef56c1102 100644
--- a/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js
+++ b/Libraries/LibJS/Tests/builtins/Function/Function.prototype.toString.js
@@ -1,21 +1,15 @@
-load("test-common.js");
-
-try {
- assert((function() {}).toString() === "function () {\n ???\n}");
- assert((function(foo) {}).toString() === "function (foo) {\n ???\n}");
- assert((function(foo, bar, baz) {}).toString() === "function (foo, bar, baz) {\n ???\n}");
- assert((function(foo, bar, baz) {
+test("basic functionality", () => {
+ expect((function() {}).toString()).toBe("function () {\n ???\n}");
+ expect((function(foo) {}).toString()).toBe("function (foo) {\n ???\n}");
+ expect((function(foo, bar, baz) {}).toString()).toBe("function (foo, bar, baz) {\n ???\n}");
+ expect((function(foo, bar, baz) {
if (foo) {
return baz;
} else if (bar) {
return foo;
}
return bar + 42;
- }).toString() === "function (foo, bar, baz) {\n ???\n}");
- assert(console.log.toString() === "function log() {\n [NativeFunction]\n}");
- assert(Function.toString() === "function Function() {\n [FunctionConstructor]\n}");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ }).toString()).toBe("function (foo, bar, baz) {\n ???\n}");
+ expect(console.debug.toString()).toBe("function debug() {\n [NativeFunction]\n}");
+ expect(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Infinity/Infinity-basic.js b/Libraries/LibJS/Tests/builtins/Infinity/Infinity-basic.js
deleted file mode 100644
index 9bab327822..0000000000
--- a/Libraries/LibJS/Tests/builtins/Infinity/Infinity-basic.js
+++ /dev/null
@@ -1,27 +0,0 @@
-load("test-common.js");
-
-try {
- assert(Infinity + "" === "Infinity");
- assert(-Infinity + "" === "-Infinity");
- assert(Infinity === Infinity);
- assert(Infinity - 1 === Infinity);
- assert(Infinity + 1 === Infinity);
- assert(-Infinity === -Infinity);
- assert(-Infinity - 1 === -Infinity);
- assert(-Infinity + 1 === -Infinity);
- assert(1 / Infinity === 0);
- assert(1 / -Infinity === 0);
- assert(1 / 0 === Infinity);
- assert(-1 / 0 === -Infinity);
- assert(-100 < Infinity);
- assert(0 < Infinity);
- assert(100 < Infinity);
- assert(-Infinity < Infinity);
- assert(-100 > -Infinity);
- assert(0 > -Infinity);
- assert(100 > -Infinity);
- assert(Infinity > -Infinity);
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
diff --git a/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js b/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js
new file mode 100644
index 0000000000..0c88544f7f
--- /dev/null
+++ b/Libraries/LibJS/Tests/builtins/Infinity/Infinity.js
@@ -0,0 +1,22 @@
+test("basic functionality", () => {
+ expect(Infinity + "").toBe("Infinity");
+ expect(-Infinity + "").toBe("-Infinity");
+ expect(Infinity).toBe(Infinity);
+ expect(Infinity - 1).toBe(Infinity);
+ expect(Infinity + 1).toBe(Infinity);
+ expect(-Infinity).toBe(-Infinity);
+ expect(-Infinity - 1).toBe(-Infinity);
+ expect(-Infinity + 1).toBe(-Infinity);
+ expect(1 / Infinity).toBe(0);
+ expect(1 / -Infinity).toBe(-0);
+ expect(1 / 0).toBe(Infinity);
+ expect(-1 / 0).toBe(-Infinity);
+ expect(-100).toBeLessThan(Infinity);
+ expect(0).toBeLessThan(Infinity);
+ expect(100).toBeLessThan(Infinity);
+ expect(-Infinity).toBeLessThan(Infinity);
+ expect(-100).toBeGreaterThan(-Infinity);
+ expect(0).toBeGreaterThan(-Infinity);
+ expect(100).toBeGreaterThan(-Infinity);
+ expect(Infinity).toBeGreaterThan(-Infinity);
+});
diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js
index aa2d92b24d..db77a1b17b 100644
--- a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js
+++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse-reviver.js
@@ -1,15 +1,9 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`;
let object = JSON.parse(string, (key, value) => typeof value === "number" ? value * 2 : value);
- assertDeepEquals(object, { var1: 20, var2: "hello", var3: { nested: 10 } });
+ expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } });
object = JSON.parse(string, (key, value) => typeof value === "number" ? undefined : value);
- assertDeepEquals(object, { var2: "hello", var3: {} });
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(object).toEqual({ var2: "hello", var3: {} });
+});
diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js
index 40f79cee60..7f82392666 100644
--- a/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js
+++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js
@@ -1,7 +1,5 @@
-load("test-common.js");
-
-try {
- assert(JSON.parse.length === 2);
+test("basic functionality", () => {
+ expect(JSON.parse).toHaveLength(2);
const properties = [
["5", 5],
@@ -14,10 +12,12 @@ try {
];
properties.forEach(testCase => {
- assertDeepEquals(JSON.parse(testCase[0]), testCase[1]);
+ expect(JSON.parse(testCase[0])).toEqual(testCase[1]);
});
+});
- let syntaxErrors = [
+test("syntax errors", () => {
+ [
undefined,
NaN,
-NaN,
@@ -29,15 +29,9 @@ try {
"[1,2,3, ]",
'{ "foo": "bar",}',
'{ "foo": "bar", }',
- ];
-
- syntaxErrors.forEach(error => assertThrowsError(() => {
- JSON.parse(error);
- }, {
- error: SyntaxError,
- }));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ ].forEach(test => {
+ expect(() => {
+ JSON.parse(test);
+ }).toThrow(SyntaxError);
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js
index 6dfab9e3df..3edede22f1 100644
--- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js
+++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-order.js
@@ -1,8 +1,4 @@
-load("test-common.js");
-
-try {
- assert(JSON.stringify.length === 3);
-
+test("basic functionality", () => {
let o = {
key1: "key1",
key2: "key2",
@@ -28,9 +24,5 @@ try {
o.key1 = "key1";
- assert(JSON.stringify(o) === '{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}');
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(JSON.stringify(o)).toBe('{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}');
+});
diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js
index 4db7b22b41..3d483a01e8 100644
--- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js
+++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-proxy.js
@@ -1,6 +1,4 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
let p = new Proxy([], {
get(_, key) {
if (key === "length")
@@ -9,10 +7,6 @@ try {
},
});
- assert(JSON.stringify(p) === "[0,1,2]");
- assert(JSON.stringify([[new Proxy(p, {})]]) === "[[[0,1,2]]]");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(JSON.stringify(p)).toBe("[0,1,2]");
+ expect(JSON.stringify([[new Proxy(p, {})]])).toBe("[[[0,1,2]]]");
+});
diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js
index e994d25ae4..b0f6eda72b 100644
--- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js
+++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-replacer.js
@@ -1,6 +1,4 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
let o = {
var1: "foo",
var2: 42,
@@ -25,15 +23,11 @@ try {
return value;
});
- assert(string === '{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}');
+ expect(string).toBe('{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}');
string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]);
- assert(string == '{"var1":"foo","var2":42,"obj":{}}');
+ expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}');
string = JSON.stringify(o, ["var1", "var1", "var2", "obj", "subarr"]);
- assert(string == '{"var1":"foo","var2":42,"obj":{"subarr":[3]}}');
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(string).toBe('{"var1":"foo","var2":42,"obj":{"subarr":[3]}}');
+});
diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js
index 33d49545a8..a1401560cf 100644
--- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js
+++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js
@@ -1,6 +1,4 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
let o = {
foo: 1,
bar: "baz",
@@ -26,7 +24,7 @@ try {
}
}`;
- assert(string === expected);
+ expect(string).toBe(expected);
string = JSON.stringify(o, null, "abcd");
expected =
@@ -43,9 +41,5 @@ abcdabcd]
abcd}
}`;
- assert(string === expected);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(string).toBe(expected);
+});
diff --git a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js
index d071ea961b..7b9925b0e3 100644
--- a/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js
+++ b/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify.js
@@ -1,71 +1,71 @@
-load("test-common.js");
-
-try {
- assert(JSON.stringify.length === 3);
-
- assertThrowsError(() => {
- JSON.stringify(5n);
- }, {
- error: TypeError,
- message: "Cannot serialize BigInt value to JSON",
+describe("correct behavior", () => {
+ test("length", () => {
+ expect(JSON.stringify).toHaveLength(3);
});
- const properties = [
- [5, "5"],
- [undefined, undefined],
- [null, "null"],
- [NaN, "null"],
- [-NaN, "null"],
- [Infinity, "null"],
- [-Infinity, "null"],
- [true, "true"],
- [false, "false"],
- ["test", '"test"'],
- [new Number(5), "5"],
- [new Boolean(false), "false"],
- [new String("test"), '"test"'],
- [() => {}, undefined],
- [[1, 2, "foo"], '[1,2,"foo"]'],
- [{ foo: 1, bar: "baz", qux() {} }, '{"foo":1,"bar":"baz"}'],
+ test("basic functionality", () => {
[
- {
- var1: 1,
- var2: 2,
- toJSON(key) {
- let o = this;
- o.var2 = 10;
- return o;
- }
- },
- '{"var1":1,"var2":10}',
- ],
- ];
-
- properties.forEach(testCase => {
- assert(JSON.stringify(testCase[0]) === testCase[1]);
+ [5, "5"],
+ [undefined, undefined],
+ [null, "null"],
+ [NaN, "null"],
+ [-NaN, "null"],
+ [Infinity, "null"],
+ [-Infinity, "null"],
+ [true, "true"],
+ [false, "false"],
+ ["test", '"test"'],
+ [new Number(5), "5"],
+ [new Boolean(false), "false"],
+ [new String("test"), '"test"'],
+ [() => {}, undefined],
+ [[1, 2, "foo"], '[1,2,"foo"]'],
+ [{ foo: 1, bar: "baz", qux() {} }, '{"foo":1,"bar":"baz"}'],
+ [
+ {
+ var1: 1,
+ var2: 2,
+ toJSON(key) {
+ let o = this;
+ o.var2 = 10;
+ return o;
+ }
+ },
+ '{"var1":1,"var2":10}',
+ ],
+ ].forEach(testCase => {
+ expect(JSON.stringify(testCase[0])).toEqual(testCase[1]);
+ });
});
- let bad1 = {};
- bad1.foo = bad1;
- let bad2 = [];
- bad2[5] = [[[bad2]]];
+ test("ignores non-enumerable properties", () => {
+ let o = { foo: "bar" };
+ Object.defineProperty(o, "baz", { value: "qux", enumerable: false });
+ expect(JSON.stringify(o)).toBe('{"foo":"bar"}');
+ });
+});
- let bad3a = { foo: "bar" };
- let bad3b = [1, 2, bad3a];
- bad3a.bad = bad3b;
+describe("errors", () => {
+ test("cannot serialize BigInt", () => {
+ expect(() => {
+ JSON.stringify(5n);
+ }).toThrow(TypeError, "Cannot serialize BigInt value to JSON");
+ });
- [bad1, bad2, bad3a].forEach(bad => assertThrowsError(() => {
- JSON.stringify(bad);
- }, {
- error: TypeError,
- message: "Cannot stringify circular object",
- }));
+ test("cannot serialize circular structures", () => {
+ let bad1 = {};
+ bad1.foo = bad1;
+ let bad2 = [];
+ bad2[5] = [[[bad2]]];
- let o = { foo: "bar" };
- Object.defineProperty(o, "baz", { value: "qux", enumerable: false });
- assert(JSON.stringify(o) === '{"foo":"bar"}');
+ let bad3a = { foo: "bar" };
+ let bad3b = [1, 2, bad3a];
+ bad3a.bad = bad3b;
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ [bad1, bad2, bad3a].forEach(bad => {
+ expect(() => {
+ JSON.stringify(bad);
+ }).toThrow(TypeError, "Cannot stringify circular object");
+ });
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math-constants.js b/Libraries/LibJS/Tests/builtins/Math/Math-constants.js
index caf0141ba2..f8c75c269b 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math-constants.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math-constants.js
@@ -1,16 +1,10 @@
-load("test-common.js");
-
-try {
- assert(isClose(Math.E, 2.718281));
- assert(isClose(Math.LN2, 0.693147));
- assert(isClose(Math.LN10, 2.302585));
- assert(isClose(Math.LOG2E, 1.442695));
- assert(isClose(Math.LOG10E, 0.434294));
- assert(isClose(Math.PI, 3.1415926));
- assert(isClose(Math.SQRT1_2, 0.707106));
- assert(isClose(Math.SQRT2, 1.414213));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Math.E).toBeCloseTo(2.718281);
+ expect(Math.LN2).toBeCloseTo(0.693147);
+ expect(Math.LN10).toBeCloseTo(2.302585);
+ expect(Math.LOG2E).toBeCloseTo(1.442695);
+ expect(Math.LOG10E).toBeCloseTo(0.434294);
+ expect(Math.PI).toBeCloseTo(3.1415926);
+ expect(Math.SQRT1_2).toBeCloseTo(0.707106);
+ expect(Math.SQRT2).toBeCloseTo(1.414213);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.abs.js b/Libraries/LibJS/Tests/builtins/Math/Math.abs.js
index 583af24dfa..e051337c2c 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.abs.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.abs.js
@@ -1,16 +1,14 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.abs).toHaveLength(1);
-try {
- assert(Math.abs('-1') === 1);
- assert(Math.abs(-2) === 2);
- assert(Math.abs(null) === 0);
- assert(Math.abs('') === 0);
- assert(Math.abs([]) === 0);
- assert(Math.abs([2]) === 2);
- assert(isNaN(Math.abs([1, 2])));
- assert(isNaN(Math.abs({})));
- assert(isNaN(Math.abs('string')));
- assert(isNaN(Math.abs()));
- console.log("PASS");
-} catch {
-}
+ expect(Math.abs('-1')).toBe(1);
+ expect(Math.abs(-2)).toBe(2);
+ expect(Math.abs(null)).toBe(0);
+ expect(Math.abs('')).toBe(0);
+ expect(Math.abs([])).toBe(0);
+ expect(Math.abs([2])).toBe(2);
+ expect(Math.abs([1, 2])).toBeNaN();
+ expect(Math.abs({})).toBeNaN();
+ expect(Math.abs('string')).toBeNaN();
+ expect(Math.abs()).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js b/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js
index fbf59e7989..e7705e1e2e 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.acosh.js
@@ -1,13 +1,9 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.acosh).toHaveLength(1);
-try {
- assert(isNaN(Math.acosh(-1)));
- assert(isNaN(Math.acosh(0)));
- assert(isNaN(Math.acosh(0.5)));
- assert(isClose(Math.acosh(1), 0));
- // FIXME: assert(isClose(Math.acosh(2), 1.316957));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.acosh(-1)).toBeNaN();
+ expect(Math.acosh(0)).toBeNaN();
+ expect(Math.acosh(0.5)).toBeNaN();
+ expect(Math.acosh(1)).toBeCloseTo(0);
+ // FIXME: expect(Math.acosh(2)).toBeCloseTo(1.316957);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js b/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js
index fdb97f0428..84502b9420 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js
@@ -1,11 +1,6 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.asinh).toHaveLength(1);
-try {
- assert(isClose(Math.asinh(0), 0));
-
- // FIXME: assert(isClose(Math.asinh(1), 0.881373));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.asinh(0)).toBeCloseTo(0);
+ // FIXME: expect(Math.asinh(1)).toBeCloseTo(0.881373);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js b/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js
index e4809c9a07..1403f207cf 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.atanh.js
@@ -1,14 +1,10 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.atanh).toHaveLength(1);
-try {
- assert(isNaN(Math.atanh(-2)));
- assert(Math.atanh(-1) === -Infinity);
- // FIXME: assert(Math.atanh(0) === 0);
- assert(isClose(Math.atanh(0.5), 0.549306));
- // FIXME: assert(Math.atanh(1) === Infinity);
- assert(isNaN(Math.atanh(2)));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.atanh(-2)).toBeNaN();
+ expect(Math.atanh(2)).toBeNaN();
+ expect(Math.atanh(-1)).toBe(-Infinity);
+ // FIXME: expect(Math.atanh(0)).toBe(0);
+ expect(Math.atanh(0.5)).toBeCloseTo(0.549306);
+ // FIXME: expect(Math.atanh(1)).toBe(Infinity);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js b/Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js
index 5f705ff7e3..a77ed22322 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.cbrt.js
@@ -1,16 +1,12 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.cbrt).toHaveLength(1);
-try {
- assert(isNaN(Math.cbrt(NaN)));
- // FIXME: assert(Math.cbrt(-1) === -1);
- assert(Math.cbrt(-0) === -0);
- // FIXME: assert(Math.cbrt(-Infinity) === -Infinity);
- // FIXME: assert(Math.cbrt(1) === 1);
- // FIXME: assert(Math.cbrt(Infinity) === Infinity);
- assert(Math.cbrt(null) === 0);
- // FIXME: assert(isClose(Math.cbrt(2), 1.259921));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.cbrt(NaN)).toBeNaN();
+ // FIXME: expect(Math.cbrt(-1)).toBe(-1);
+ expect(Math.cbrt(-0)).toBe(-0);
+ // FIXME: expect(Math.cbrt(-Infinity)).toBe(-Infinity);
+ // FIXME: expect(Math.cbrt(1)).toBe(1);
+ // FIXME: expect(Math.cbrt(Infinity)).toBe(Infinity);
+ expect(Math.cbrt(null)).toBe(0);
+ // FIXME: expect(Math.cbrt(2)).toBeCloseTo(1.259921));
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.ceil.js b/Libraries/LibJS/Tests/builtins/Math/Math.ceil.js
index 56a6ff6269..8d6208f40c 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.ceil.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.ceil.js
@@ -1,19 +1,13 @@
-load("test-common.js");
-
-try {
- assert(Math.ceil(0.95) === 1);
- assert(Math.ceil(4) === 4);
- assert(Math.ceil(7.004) == 8);
- assert(Math.ceil(-0.95) === -0);
- assert(Math.ceil(-4) === -4);
- assert(Math.ceil(-7.004) === -7);
-
- assert(isNaN(Math.ceil()));
- assert(isNaN(Math.ceil(NaN)));
-
- assert(Math.ceil.length === 1);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Math.ceil).toHaveLength(1);
+
+ expect(Math.ceil(0.95)).toBe(1);
+ expect(Math.ceil(4)).toBe(4);
+ expect(Math.ceil(7.004)).toBe(8);
+ expect(Math.ceil(-0.95)).toBe(-0);
+ expect(Math.ceil(-4) ).toBe(-4);
+ expect(Math.ceil(-7.004)).toBe(-7);
+
+ expect(Math.ceil()).toBeNaN();
+ expect(Math.ceil(NaN)).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.clz32.js b/Libraries/LibJS/Tests/builtins/Math/Math.clz32.js
index ee37c9212d..e80f9f023e 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.clz32.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.clz32.js
@@ -1,50 +1,44 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.clz32).toHaveLength(1);
-try {
- assert(Math.clz32.length === 1);
+ expect(Math.clz32(0)).toBe(32);
+ expect(Math.clz32(1)).toBe(31);
+ expect(Math.clz32(2)).toBe(30);
+ expect(Math.clz32(3)).toBe(30);
+ expect(Math.clz32(4)).toBe(29);
+ expect(Math.clz32(5)).toBe(29);
+ expect(Math.clz32(-1)).toBe(0);
+ expect(Math.clz32(-10)).toBe(0);
+ expect(Math.clz32(-100)).toBe(0);
+ expect(Math.clz32(-1000)).toBe(0);
+ expect(Math.clz32(-0.123)).toBe(32);
+ expect(Math.clz32(0.123)).toBe(32);
+ expect(Math.clz32(1.23)).toBe(31);
+ expect(Math.clz32(12)).toBe(28);
+ expect(Math.clz32(123)).toBe(25);
+ expect(Math.clz32(1234)).toBe(21);
+ expect(Math.clz32(12345)).toBe(18);
+ expect(Math.clz32(123456)).toBe(15);
+ expect(Math.clz32(1234567)).toBe(11);
+ expect(Math.clz32(12345678)).toBe(8);
+ expect(Math.clz32(123456789)).toBe(5);
+ expect(Math.clz32(999999999)).toBe(2);
+ expect(Math.clz32(9999999999)).toBe(1);
+ expect(Math.clz32(99999999999)).toBe(1);
+ expect(Math.clz32(999999999999)).toBe(0);
+ expect(Math.clz32(9999999999999)).toBe(1);
+ expect(Math.clz32(99999999999999)).toBe(3);
+ expect(Math.clz32(999999999999999)).toBe(0);
- assert(Math.clz32(0) === 32);
- assert(Math.clz32(1) === 31);
- assert(Math.clz32(2) === 30);
- assert(Math.clz32(3) === 30);
- assert(Math.clz32(4) === 29);
- assert(Math.clz32(5) === 29);
- assert(Math.clz32(-1) === 0);
- assert(Math.clz32(-10) === 0);
- assert(Math.clz32(-100) === 0);
- assert(Math.clz32(-1000) === 0);
- assert(Math.clz32(-0.123) === 32);
- assert(Math.clz32(0.123) === 32);
- assert(Math.clz32(1.23) === 31);
- assert(Math.clz32(12) === 28);
- assert(Math.clz32(123) === 25);
- assert(Math.clz32(1234) === 21);
- assert(Math.clz32(12345) === 18);
- assert(Math.clz32(123456) === 15);
- assert(Math.clz32(1234567) === 11);
- assert(Math.clz32(12345678) === 8);
- assert(Math.clz32(123456789) === 5);
- assert(Math.clz32(999999999) === 2);
- assert(Math.clz32(9999999999) === 1);
- assert(Math.clz32(99999999999) === 1);
- assert(Math.clz32(999999999999) === 0);
- assert(Math.clz32(9999999999999) === 1);
- assert(Math.clz32(99999999999999) === 3);
- assert(Math.clz32(999999999999999) === 0);
-
- assert(Math.clz32() === 32);
- assert(Math.clz32(NaN) === 32);
- assert(Math.clz32(Infinity) === 32);
- assert(Math.clz32(-Infinity) === 32);
- assert(Math.clz32(false) === 32);
- assert(Math.clz32(true) === 31);
- assert(Math.clz32(null) === 32);
- assert(Math.clz32(undefined) === 32);
- assert(Math.clz32([]) === 32);
- assert(Math.clz32({}) === 32);
- assert(Math.clz32("foo") === 32);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.clz32()).toBe(32);
+ expect(Math.clz32(NaN)).toBe(32);
+ expect(Math.clz32(Infinity)).toBe(32);
+ expect(Math.clz32(-Infinity)).toBe(32);
+ expect(Math.clz32(false)).toBe(32);
+ expect(Math.clz32(true)).toBe(31);
+ expect(Math.clz32(null)).toBe(32);
+ expect(Math.clz32(undefined)).toBe(32);
+ expect(Math.clz32([])).toBe(32);
+ expect(Math.clz32({})).toBe(32);
+ expect(Math.clz32("foo")).toBe(32);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.cos.js b/Libraries/LibJS/Tests/builtins/Math/Math.cos.js
index e483243ae4..020a438498 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.cos.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.cos.js
@@ -1,18 +1,14 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.cos).toHaveLength(1);
-try {
- assert(Math.cos(0) === 1);
- assert(Math.cos(null) === 1);
- assert(Math.cos('') === 1);
- assert(Math.cos([]) === 1);
- assert(Math.cos(Math.PI) === -1);
- assert(isNaN(Math.cos()));
- assert(isNaN(Math.cos(undefined)));
- assert(isNaN(Math.cos([1, 2, 3])));
- assert(isNaN(Math.cos({})));
- assert(isNaN(Math.cos("foo")));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.cos(0)).toBe(1);
+ expect(Math.cos(null)).toBe(1);
+ expect(Math.cos('')).toBe(1);
+ expect(Math.cos([])).toBe(1);
+ expect(Math.cos(Math.PI)).toBe(-1);
+ expect(Math.cos()).toBeNaN();
+ expect(Math.cos(undefined)).toBeNaN();
+ expect(Math.cos([1, 2, 3])).toBeNaN();
+ expect(Math.cos({})).toBeNaN();
+ expect(Math.cos("foo")).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.exp.js b/Libraries/LibJS/Tests/builtins/Math/Math.exp.js
index 737ebf3f3a..d7111be916 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.exp.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.exp.js
@@ -1,19 +1,13 @@
-load("test-common.js");
-
-try {
- assert(Math.exp.length === 1);
-
- assert(Math.exp(0) === 1);
- assert(isClose(Math.exp(-2), 0.135335));
- assert(isClose(Math.exp(-1), 0.367879));
- assert(isClose(Math.exp(1), 2.718281));
- assert(isClose(Math.exp(2), 7.389056));
-
- assert(isNaN(Math.exp()));
- assert(isNaN(Math.exp(undefined)));
- assert(isNaN(Math.exp("foo")));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Math.exp).toHaveLength(1);
+
+ expect(Math.exp(0)).toBe(1);
+ expect(Math.exp(-2)).toBeCloseTo(0.135335);
+ expect(Math.exp(-1)).toBeCloseTo(0.367879);
+ expect(Math.exp(1)).toBeCloseTo(2.718281);
+ expect(Math.exp(2)).toBeCloseTo(7.389056);
+
+ expect(Math.exp()).toBeNaN();
+ expect(Math.exp(undefined)).toBeNaN();
+ expect(Math.exp("foo")).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.expm1.js b/Libraries/LibJS/Tests/builtins/Math/Math.expm1.js
index 45f3c2be54..4d7c31b922 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.expm1.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.expm1.js
@@ -1,19 +1,13 @@
-load("test-common.js");
-
-try {
- assert(Math.expm1.length === 1);
-
- assert(Math.expm1(0) === 0);
- assert(isClose(Math.expm1(-2), -0.864664));
- assert(isClose(Math.expm1(-1), -0.632120));
- assert(isClose(Math.expm1(1), 1.718281));
- assert(isClose(Math.expm1(2), 6.389056));
-
- assert(isNaN(Math.expm1()));
- assert(isNaN(Math.expm1(undefined)));
- assert(isNaN(Math.expm1("foo")));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Math.expm1).toHaveLength(1);
+
+ expect(Math.expm1(0)).toBe(0);
+ expect(Math.expm1(-2)).toBeCloseTo(-0.864664);
+ expect(Math.expm1(-1)).toBeCloseTo(-0.632120);
+ expect(Math.expm1(1)).toBeCloseTo(1.718281);
+ expect(Math.expm1(2)).toBeCloseTo(6.389056);
+
+ expect(Math.expm1()).toBeNaN();
+ expect(Math.expm1(undefined)).toBeNaN();
+ expect(Math.expm1("foo")).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.floor.js b/Libraries/LibJS/Tests/builtins/Math/Math.floor.js
index c636398969..f1420fe202 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.floor.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.floor.js
@@ -1,19 +1,13 @@
-load("test-common.js");
-
-try {
- assert(Math.floor(0.95) === 0);
- assert(Math.floor(4) === 4);
- assert(Math.floor(7.004) == 7);
- assert(Math.floor(-0.95) === -1);
- assert(Math.floor(-4) === -4);
- assert(Math.floor(-7.004) === -8);
-
- assert(isNaN(Math.floor()));
- assert(isNaN(Math.floor(NaN)));
-
- assert(Math.floor.length === 1);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Math.floor).toHaveLength(1);
+
+ expect(Math.floor(0.95)).toBe(0);
+ expect(Math.floor(4)).toBe(4);
+ expect(Math.floor(7.004)).toBe(7);
+ expect(Math.floor(-0.95)).toBe(-1);
+ expect(Math.floor(-4)).toBe(-4);
+ expect(Math.floor(-7.004)).toBe(-8);
+
+ expect(Math.floor()).toBeNaN();
+ expect(Math.floor(NaN)).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js b/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js
index ea53c12ab4..6b15c29b31 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.log1p.js
@@ -1,13 +1,8 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.log1p).toHaveLength(1);
-try {
- assert(isNaN(Math.log1p(-2)));
- assert(Math.log1p(-1) === -Infinity);
- // FIXME: assert(Math.log1p(0) === 0);
- // FIXME: assert(isClose(Math.log1p(1), 0.693147));
-
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.log1p(-2)).toBeNaN();
+ expect(Math.log1p(-1)).toBe(-Infinity);
+ // FIXME: expect(Math.log1p(0)).toBe(0);
+ // FIXME: expect(Math.log1p(1)).toBeCloseTo(0.693147);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.max.js b/Libraries/LibJS/Tests/builtins/Math/Math.max.js
index 7b01e44102..f99a39cc9c 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.max.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.max.js
@@ -1,15 +1,10 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.max).toHaveLength(2);
-try {
- assert(Math.max.length === 2);
- assert(Math.max() === -Infinity);
- assert(Math.max(1) === 1);
- assert(Math.max(2, 1) === 2);
- assert(Math.max(1, 2, 3) === 3);
- assert(isNaN(Math.max(NaN)));
- assert(isNaN(Math.max("String", 1)));
-
- console.log("PASS");
-} catch {
- console.log("FAIL");
-}
+ expect(Math.max()).toBe(-Infinity);
+ expect(Math.max(1)).toBe(1);
+ expect(Math.max(2, 1)).toBe(2);
+ expect(Math.max(1, 2, 3)).toBe(3);
+ expect(Math.max(NaN)).toBeNaN();
+ expect(Math.max("String", 1)).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.min.js b/Libraries/LibJS/Tests/builtins/Math/Math.min.js
index fbe26bd27b..fedfcabe27 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.min.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.min.js
@@ -1,14 +1,9 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.min).toHaveLength(2);
-try {
- assert(Math.min.length === 2);
- assert(Math.min(1) === 1);
- assert(Math.min(2, 1) === 1);
- assert(Math.min(1, 2, 3) === 1);
- assert(isNaN(Math.min(NaN)));
- assert(isNaN(Math.min("String", 1)));
-
- console.log("PASS");
-} catch {
- console.log("FAIL");
-}
+ expect(Math.min(1)).toBe(1);
+ expect(Math.min(2, 1)).toBe(1);
+ expect(Math.min(1, 2, 3)).toBe(1);
+ expect(Math.min(NaN)).toBeNaN();
+ expect(Math.min("String", 1)).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.pow.js b/Libraries/LibJS/Tests/builtins/Math/Math.pow.js
index b4e7670a1c..036060b238 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.pow.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.pow.js
@@ -1,29 +1,25 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.pow).toHaveLength(2);
-try {
- assert(Math.pow(2, 0) === 1);
- assert(Math.pow(2, 1) === 2);
- assert(Math.pow(2, 2) === 4);
- assert(Math.pow(2, 3) === 8);
- assert(Math.pow(2, -3) === 0.125);
- assert(Math.pow(3, 2) === 9);
- assert(Math.pow(0, 0) === 1);
- assert(Math.pow(2, Math.pow(3, 2)) === 512);
- assert(Math.pow(Math.pow(2, 3), 2) === 64);
- assert(Math.pow("2", "3") === 8);
- assert(Math.pow("", []) === 1);
- assert(Math.pow([], null) === 1);
- assert(Math.pow(null, null) === 1);
- assert(Math.pow(undefined, null) === 1);
- assert(isNaN(Math.pow(NaN, 2)));
- assert(isNaN(Math.pow(2, NaN)));
- assert(isNaN(Math.pow(undefined, 2)));
- assert(isNaN(Math.pow(2, undefined)));
- assert(isNaN(Math.pow(null, undefined)));
- assert(isNaN(Math.pow(2, "foo")));
- assert(isNaN(Math.pow("foo", 2)));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.pow(2, 0)).toBe(1);
+ expect(Math.pow(2, 1)).toBe(2);
+ expect(Math.pow(2, 2)).toBe(4);
+ expect(Math.pow(2, 3)).toBe(8);
+ expect(Math.pow(2, -3)).toBe(0.125);
+ expect(Math.pow(3, 2)).toBe(9);
+ expect(Math.pow(0, 0)).toBe(1);
+ expect(Math.pow(2, Math.pow(3, 2))).toBe(512);
+ expect(Math.pow(Math.pow(2, 3), 2)).toBe(64);
+ expect(Math.pow("2", "3")).toBe(8);
+ expect(Math.pow("", [])).toBe(1);
+ expect(Math.pow([], null)).toBe(1);
+ expect(Math.pow(null, null)).toBe(1);
+ expect(Math.pow(undefined, null)).toBe(1);
+ expect(Math.pow(NaN, 2)).toBeNaN();
+ expect(Math.pow(2, NaN)).toBeNaN();
+ expect(Math.pow(undefined, 2)).toBeNaN();
+ expect(Math.pow(2, undefined)).toBeNaN();
+ expect(Math.pow(null, undefined)).toBeNaN();
+ expect(Math.pow(2, "foo")).toBeNaN();
+ expect(Math.pow("foo", 2)).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sign.js b/Libraries/LibJS/Tests/builtins/Math/Math.sign.js
index e60233b8cb..1a62b7fc9f 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.sign.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.sign.js
@@ -1,5 +1,3 @@
-load("test-common.js");
-
function isPositiveZero(value) {
return value === 0 && 1 / value === Infinity;
}
@@ -8,35 +6,33 @@ function isNegativeZero(value) {
return value === 0 && 1 / value === -Infinity;
}
-try {
- assert(Math.sign.length === 1);
+test("basic functionality", () => {
+ expect(Math.sign).toHaveLength(1);
- assert(Math.sign(0.0001) === 1);
- assert(Math.sign(1) === 1);
- assert(Math.sign(42) === 1);
- assert(Math.sign(Infinity) === 1);
- assert(isPositiveZero(Math.sign(0)));
- assert(isPositiveZero(Math.sign(null)));
- assert(isPositiveZero(Math.sign('')));
- assert(isPositiveZero(Math.sign([])));
+ expect(Math.sign.length).toBe(1);
- assert(Math.sign(-0.0001) === -1);
- assert(Math.sign(-1) === -1);
- assert(Math.sign(-42) === -1);
- assert(Math.sign(-Infinity) === -1);
- assert(isNegativeZero(Math.sign(-0)));
- assert(isNegativeZero(Math.sign(-null)));
- assert(isNegativeZero(Math.sign(-'')));
- assert(isNegativeZero(Math.sign(-[])));
+ expect(Math.sign(0.0001)).toBe(1);
+ expect(Math.sign(1)).toBe(1);
+ expect(Math.sign(42)).toBe(1);
+ expect(Math.sign(Infinity)).toBe(1);
+ expect(isPositiveZero(Math.sign(0))).toBeTrue();
+ expect(isPositiveZero(Math.sign(null))).toBeTrue();
+ expect(isPositiveZero(Math.sign(''))).toBeTrue();
+ expect(isPositiveZero(Math.sign([]))).toBeTrue();
- assert(isNaN(Math.sign()));
- assert(isNaN(Math.sign(undefined)));
- assert(isNaN(Math.sign([1, 2, 3])));
- assert(isNaN(Math.sign({})));
- assert(isNaN(Math.sign(NaN)));
- assert(isNaN(Math.sign("foo")));
+ expect(Math.sign(-0.0001)).toBe(-1);
+ expect(Math.sign(-1)).toBe(-1);
+ expect(Math.sign(-42)).toBe(-1);
+ expect(Math.sign(-Infinity)).toBe(-1);
+ expect(isNegativeZero(Math.sign(-0))).toBeTrue();
+ expect(isNegativeZero(Math.sign(-null))).toBeTrue();
+ expect(isNegativeZero(Math.sign(-''))).toBeTrue();
+ expect(isNegativeZero(Math.sign(-[]))).toBeTrue();
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.sign()).toBeNaN();
+ expect(Math.sign(undefined)).toBeNaN();
+ expect(Math.sign([1, 2, 3])).toBeNaN();
+ expect(Math.sign({})).toBeNaN();
+ expect(Math.sign(NaN)).toBeNaN();
+ expect(Math.sign("foo")).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sin.js b/Libraries/LibJS/Tests/builtins/Math/Math.sin.js
index 50a591b1c9..cc590592b5 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.sin.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.sin.js
@@ -1,19 +1,15 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.sin).toHaveLength(1);
-try {
- assert(Math.sin(0) === 0);
- assert(Math.sin(null) === 0);
- assert(Math.sin('') === 0);
- assert(Math.sin([]) === 0);
- assert(Math.sin(Math.PI * 3 / 2) === -1);
- assert(Math.sin(Math.PI / 2) === 1);
- assert(isNaN(Math.sin()));
- assert(isNaN(Math.sin(undefined)));
- assert(isNaN(Math.sin([1, 2, 3])));
- assert(isNaN(Math.sin({})));
- assert(isNaN(Math.sin("foo")));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.sin(0)).toBe(0);
+ expect(Math.sin(null)).toBe(0);
+ expect(Math.sin('')).toBe(0);
+ expect(Math.sin([])).toBe(0);
+ expect(Math.sin(Math.PI * 3 / 2)).toBe(-1);
+ expect(Math.sin(Math.PI / 2)).toBe(1);
+ expect(Math.sin()).toBeNaN();
+ expect(Math.sin(undefined)).toBeNaN();
+ expect(Math.sin([1, 2, 3])).toBeNaN();
+ expect(Math.sin({})).toBeNaN();
+ expect(Math.sin("foo")).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js b/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js
index 622fd8b198..1e7b2115e0 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.sqrt.js
@@ -1,7 +1,4 @@
-load("test-common.js");
-
-try {
- assert(Math.sqrt(9) === 3);
- console.log("PASS");
-} catch {
-}
+test("basic functionality", () => {
+ expect(Math.sqrt).toHaveLength(1);
+ expect(Math.sqrt(9)).toBe(3);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.tan.js b/Libraries/LibJS/Tests/builtins/Math/Math.tan.js
index 636fe2add7..d74a103178 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.tan.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.tan.js
@@ -1,18 +1,14 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Math.tan).toHaveLength(1);
-try {
- assert(Math.tan(0) === 0);
- assert(Math.tan(null) === 0);
- assert(Math.tan('') === 0);
- assert(Math.tan([]) === 0);
- assert(Math.ceil(Math.tan(Math.PI / 4)) === 1);
- assert(isNaN(Math.tan()));
- assert(isNaN(Math.tan(undefined)));
- assert(isNaN(Math.tan([1, 2, 3])));
- assert(isNaN(Math.tan({})));
- assert(isNaN(Math.tan("foo")));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Math.tan(0)).toBe(0);
+ expect(Math.tan(null)).toBe(0);
+ expect(Math.tan('')).toBe(0);
+ expect(Math.tan([])).toBe(0);
+ expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1);
+ expect(Math.tan()).toBeNaN();
+ expect(Math.tan(undefined)).toBeNaN();
+ expect(Math.tan([1, 2, 3])).toBeNaN();
+ expect(Math.tan({})).toBeNaN();
+ expect(Math.tan("foo")).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js b/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js
index 79b257b176..b3e4eafaeb 100644
--- a/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js
+++ b/Libraries/LibJS/Tests/builtins/Math/Math.trunc.js
@@ -1,18 +1,12 @@
-load("test-common.js")
-
-try {
- assert(Math.trunc(13.37) === 13);
- assert(Math.trunc(42.84) === 42);
- assert(Math.trunc(0.123) === 0);
- assert(Math.trunc(-0.123) === -0);
-
- assert(isNaN(Math.trunc(NaN)));
- assert(isNaN(Math.trunc('foo')));
- assert(isNaN(Math.trunc()));
-
- assert(Math.trunc.length === 1);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Math.trunc).toHaveLength(1);
+
+ expect(Math.trunc(13.37)).toBe(13);
+ expect(Math.trunc(42.84)).toBe(42);
+ expect(Math.trunc(0.123)).toBe( 0);
+ expect(Math.trunc(-0.123)).toBe(-0);
+
+ expect(Math.trunc(NaN)).toBeNaN();
+ expect(Math.trunc('foo')).toBeNaN();
+ expect(Math.trunc()).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/NaN/NaN-basic.js b/Libraries/LibJS/Tests/builtins/NaN/NaN-basic.js
deleted file mode 100644
index 188d9347e3..0000000000
--- a/Libraries/LibJS/Tests/builtins/NaN/NaN-basic.js
+++ /dev/null
@@ -1,21 +0,0 @@
-load("test-common.js");
-
-try {
- var nan = undefined + 1;
- assert(nan + "" == "NaN");
- assert(NaN + "" == "NaN");
- assert(nan !== nan);
- assert(NaN !== NaN);
- assert(isNaN(nan) === true);
- assert(isNaN(NaN) === true);
- assert(isNaN(0) === false);
- assert(isNaN(undefined) === true);
- assert(isNaN(null) === false);
- assert(isNaN(Infinity) === false);
- assert(!!NaN === false);
- assert(!!nan === false);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
diff --git a/Libraries/LibJS/Tests/builtins/NaN/NaN.js b/Libraries/LibJS/Tests/builtins/NaN/NaN.js
new file mode 100644
index 0000000000..9c496238b9
--- /dev/null
+++ b/Libraries/LibJS/Tests/builtins/NaN/NaN.js
@@ -0,0 +1,13 @@
+test("basic functionality", () => {
+ const nan = undefined + 1;
+
+ expect(nan + "").toBe("NaN");
+ expect(NaN + "").toBe("NaN");
+ expect(nan !== nan).toBeTrue();
+ expect(NaN !== NaN).toBeTrue();
+ expect(nan).toBeNaN();
+ expect(NaN).toBeNaN();
+ expect(0).not.toBeNaN();
+ expect(!!nan).toBeFalse();
+ expect(!!NaN).toBeFalse();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Number/Number-constants.js b/Libraries/LibJS/Tests/builtins/Number/Number-constants.js
index ce2e7a67f9..2958821546 100644
--- a/Libraries/LibJS/Tests/builtins/Number/Number-constants.js
+++ b/Libraries/LibJS/Tests/builtins/Number/Number-constants.js
@@ -1,17 +1,11 @@
-load("test-common.js");
-
-try {
- assert(Number.EPSILON === 2 ** -52);
- assert(Number.EPSILON > 0);
- assert(Number.MAX_SAFE_INTEGER === 2 ** 53 - 1);
- assert(Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2);
- assert(Number.MIN_SAFE_INTEGER === -(2 ** 53 - 1));
- assert(Number.MIN_SAFE_INTEGER - 1 === Number.MIN_SAFE_INTEGER - 2);
- assert(Number.POSITIVE_INFINITY === Infinity);
- assert(Number.NEGATIVE_INFINITY === -Infinity);
- assert(isNaN(Number.NaN));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Number.EPSILON).toBe(2 ** -52);
+ expect(Number.EPSILON).toBeGreaterThan(0);
+ expect(Number.MAX_SAFE_INTEGER).toBe(2 ** 53 - 1);
+ expect(Number.MAX_SAFE_INTEGER + 1).toBe(Number.MAX_SAFE_INTEGER + 2);
+ expect(Number.MIN_SAFE_INTEGER).toBe(-(2 ** 53 - 1));
+ expect(Number.MIN_SAFE_INTEGER - 1).toBe(Number.MIN_SAFE_INTEGER - 2);
+ expect(Number.POSITIVE_INFINITY).toBe(Infinity);
+ expect(Number.NEGATIVE_INFINITY).toBe(-Infinity);
+ expect(Number.NaN).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js b/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js
index 892b24031a..19a23c0292 100644
--- a/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js
+++ b/Libraries/LibJS/Tests/builtins/Number/Number.isFinite.js
@@ -1,30 +1,24 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Number.isFinite).toHaveLength(1);
+ expect(Number.isFinite).not.toBe(isFinite);
-try {
- assert(Number.isFinite !== isFinite);
- assert(Number.isFinite.length === 1);
+ expect(Number.isFinite(0)).toBeTrue();
+ expect(Number.isFinite(1.23)).toBeTrue();
+ expect(Number.isFinite(42)).toBeTrue();
- assert(Number.isFinite(0) === true);
- assert(Number.isFinite(1.23) === true);
- assert(Number.isFinite(42) === true);
-
- assert(Number.isFinite("") === false);
- assert(Number.isFinite("0") === false);
- assert(Number.isFinite("42") === false);
- assert(Number.isFinite(true) === false);
- assert(Number.isFinite(false) === false);
- assert(Number.isFinite(null) === false);
- assert(Number.isFinite([]) === false);
- assert(Number.isFinite() === false);
- assert(Number.isFinite(NaN) === false);
- assert(Number.isFinite(undefined) === false);
- assert(Number.isFinite(Infinity) === false);
- assert(Number.isFinite(-Infinity) === false);
- assert(Number.isFinite("foo") === false);
- assert(Number.isFinite({}) === false);
- assert(Number.isFinite([1, 2, 3]) === false);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e.message);
-}
+ expect(Number.isFinite("")).toBeFalse();
+ expect(Number.isFinite("0")).toBeFalse();
+ expect(Number.isFinite("42")).toBeFalse();
+ expect(Number.isFinite(true)).toBeFalse();
+ expect(Number.isFinite(false)).toBeFalse();
+ expect(Number.isFinite(null)).toBeFalse();
+ expect(Number.isFinite([])).toBeFalse();
+ expect(Number.isFinite()).toBeFalse();
+ expect(Number.isFinite(NaN)).toBeFalse();
+ expect(Number.isFinite(undefined)).toBeFalse();
+ expect(Number.isFinite(Infinity)).toBeFalse();
+ expect(Number.isFinite(-Infinity)).toBeFalse();
+ expect(Number.isFinite("foo")).toBeFalse();
+ expect(Number.isFinite({})).toBeFalse();
+ expect(Number.isFinite([1, 2, 3])).toBeFalse();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js b/Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js
index 8c3a94e5e1..54eafdfc6f 100644
--- a/Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js
+++ b/Libraries/LibJS/Tests/builtins/Number/Number.isInteger.js
@@ -1,38 +1,32 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Number.isInteger).toHaveLength(1);
-try {
- assert(Number.isInteger.length === 1);
-
- assert(Number.isInteger(0) === true);
- assert(Number.isInteger(42) === true);
- assert(Number.isInteger(-10000) === true);
- assert(Number.isInteger(5) === true);
- assert(Number.isInteger(5.0) === true);
- assert(Number.isInteger(5 + 1/10000000000000000) === true);
+ expect(Number.isInteger(0)).toBeTrue();
+ expect(Number.isInteger(42)).toBeTrue();
+ expect(Number.isInteger(-10000)).toBeTrue();
+ expect(Number.isInteger(5)).toBeTrue();
+ expect(Number.isInteger(5.0)).toBeTrue();
+ expect(Number.isInteger(5 + 1/10000000000000000)).toBeTrue();
// FIXME: values outside of i32's range should still return true
- // assert(Number.isInteger(+2147483647 + 1) === true);
- // assert(Number.isInteger(-2147483648 - 1) === true);
- // assert(Number.isInteger(99999999999999999999999999999999999) === true);
-
- assert(Number.isInteger(5 + 1/1000000000000000) === false);
- assert(Number.isInteger(1.23) === false);
- assert(Number.isInteger("") === false);
- assert(Number.isInteger("0") === false);
- assert(Number.isInteger("42") === false);
- assert(Number.isInteger(true) === false);
- assert(Number.isInteger(false) === false);
- assert(Number.isInteger(null) === false);
- assert(Number.isInteger([]) === false);
- assert(Number.isInteger(Infinity) === false);
- assert(Number.isInteger(-Infinity) === false);
- assert(Number.isInteger(NaN) === false);
- assert(Number.isInteger() === false);
- assert(Number.isInteger(undefined) === false);
- assert(Number.isInteger("foo") === false);
- assert(Number.isInteger({}) === false);
- assert(Number.isInteger([1, 2, 3]) === false);
+ // expect(Number.isInteger(+2147483647 + 1)).toBeTrue();
+ // expect(Number.isInteger(-2147483648 - 1)).toBeTrue();
+ // expect(Number.isInteger(99999999999999999999999999999999999)).toBeTrue();
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e.message);
-}
+ expect(Number.isInteger(5 + 1/1000000000000000)).toBeFalse();
+ expect(Number.isInteger(1.23)).toBeFalse();
+ expect(Number.isInteger("")).toBeFalse();
+ expect(Number.isInteger("0")).toBeFalse();
+ expect(Number.isInteger("42")).toBeFalse();
+ expect(Number.isInteger(true)).toBeFalse();
+ expect(Number.isInteger(false)).toBeFalse();
+ expect(Number.isInteger(null)).toBeFalse();
+ expect(Number.isInteger([])).toBeFalse();
+ expect(Number.isInteger(Infinity)).toBeFalse();
+ expect(Number.isInteger(-Infinity)).toBeFalse();
+ expect(Number.isInteger(NaN)).toBeFalse();
+ expect(Number.isInteger()).toBeFalse();
+ expect(Number.isInteger(undefined)).toBeFalse();
+ expect(Number.isInteger("foo")).toBeFalse();
+ expect(Number.isInteger({})).toBeFalse();
+ expect(Number.isInteger([1, 2, 3])).toBeFalse();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js b/Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js
index bbd3a5c9c5..6a7df463df 100644
--- a/Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js
+++ b/Libraries/LibJS/Tests/builtins/Number/Number.isNaN.js
@@ -1,31 +1,25 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Number.isNaN).toHaveLength(1);
+ expect(Number.isNaN).not.toBe(isNaN);
-try {
- assert(Number.isNaN !== isNaN);
- assert(Number.isNaN.length === 1);
+ expect(Number.isNaN(0)).toBeFalse();
+ expect(Number.isNaN(42)).toBeFalse();
+ expect(Number.isNaN("")).toBeFalse();
+ expect(Number.isNaN("0")).toBeFalse();
+ expect(Number.isNaN("42")).toBeFalse();
+ expect(Number.isNaN(true)).toBeFalse();
+ expect(Number.isNaN(false)).toBeFalse();
+ expect(Number.isNaN(null)).toBeFalse();
+ expect(Number.isNaN([])).toBeFalse();
+ expect(Number.isNaN(Infinity)).toBeFalse();
+ expect(Number.isNaN(-Infinity)).toBeFalse();
+ expect(Number.isNaN()).toBeFalse();
+ expect(Number.isNaN(undefined)).toBeFalse();
+ expect(Number.isNaN("foo")).toBeFalse();
+ expect(Number.isNaN({})).toBeFalse();
+ expect(Number.isNaN([1, 2, 3])).toBeFalse();
- assert(Number.isNaN(0) === false);
- assert(Number.isNaN(42) === false);
- assert(Number.isNaN("") === false);
- assert(Number.isNaN("0") === false);
- assert(Number.isNaN("42") === false);
- assert(Number.isNaN(true) === false);
- assert(Number.isNaN(false) === false);
- assert(Number.isNaN(null) === false);
- assert(Number.isNaN([]) === false);
- assert(Number.isNaN(Infinity) === false);
- assert(Number.isNaN(-Infinity) === false);
- assert(Number.isNaN() === false);
- assert(Number.isNaN(undefined) === false);
- assert(Number.isNaN("foo") === false);
- assert(Number.isNaN({}) === false);
- assert(Number.isNaN([1, 2, 3]) === false);
-
- assert(Number.isNaN(NaN) === true);
- assert(Number.isNaN(Number.NaN) === true);
- assert(Number.isNaN(0 / 0) === true);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e.message);
-}
+ expect(Number.isNaN(NaN)).toBeTrue();
+ expect(Number.isNaN(Number.NaN)).toBeTrue();
+ expect(Number.isNaN(0 / 0)).toBeTrue();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js b/Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js
index ffa66a1a64..3bba1682a6 100644
--- a/Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js
+++ b/Libraries/LibJS/Tests/builtins/Number/Number.isSafeInteger.js
@@ -1,30 +1,24 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Number.isSafeInteger).toHaveLength(1);
-try {
- assert(Number.isSafeInteger.length === 1);
+ expect(Number.isSafeInteger(0)).toBeTrue();
+ expect(Number.isSafeInteger(1)).toBeTrue();
+ expect(Number.isSafeInteger(2.0)).toBeTrue();
+ expect(Number.isSafeInteger(42)).toBeTrue();
+ expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER)).toBeTrue();
+ expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER)).toBeTrue();
- assert(Number.isSafeInteger(0) === true);
- assert(Number.isSafeInteger(1) === true);
- assert(Number.isSafeInteger(2.0) === true);
- assert(Number.isSafeInteger(42) === true);
- assert(Number.isSafeInteger(Number.MAX_SAFE_INTEGER) === true);
- assert(Number.isSafeInteger(Number.MIN_SAFE_INTEGER) === true);
-
- assert(Number.isSafeInteger() === false);
- assert(Number.isSafeInteger("1") === false);
- assert(Number.isSafeInteger(2.1) === false);
- assert(Number.isSafeInteger(42.42) === false);
- assert(Number.isSafeInteger("") === false);
- assert(Number.isSafeInteger([]) === false);
- assert(Number.isSafeInteger(null) === false);
- assert(Number.isSafeInteger(undefined) === false);
- assert(Number.isSafeInteger(NaN) === false);
- assert(Number.isSafeInteger(Infinity) === false);
- assert(Number.isSafeInteger(-Infinity) === false);
- assert(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1) === false);
- assert(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1) === false);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e.message);
-}
+ expect(Number.isSafeInteger()).toBeFalse();
+ expect(Number.isSafeInteger("1")).toBeFalse();
+ expect(Number.isSafeInteger(2.1)).toBeFalse();
+ expect(Number.isSafeInteger(42.42)).toBeFalse();
+ expect(Number.isSafeInteger("")).toBeFalse();
+ expect(Number.isSafeInteger([])).toBeFalse();
+ expect(Number.isSafeInteger(null)).toBeFalse();
+ expect(Number.isSafeInteger(undefined)).toBeFalse();
+ expect(Number.isSafeInteger(NaN)).toBeFalse();
+ expect(Number.isSafeInteger(Infinity)).toBeFalse();
+ expect(Number.isSafeInteger(-Infinity)).toBeFalse();
+ expect(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)).toBeFalse();
+ expect(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)).toBeFalse();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.js b/Libraries/LibJS/Tests/builtins/Number/Number.js
index 850d41eb9a..2ee0476a9e 100644
--- a/Libraries/LibJS/Tests/builtins/Number/Number.js
+++ b/Libraries/LibJS/Tests/builtins/Number/Number.js
@@ -1,39 +1,33 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Number).toHaveLength(1);
+ expect(Number.name).toBe("Number");
+ expect(Number.prototype).not.toHaveProperty("length");
-try {
- assert(Number.length === 1);
- assert(Number.name === "Number");
- assert(Number.prototype.length === undefined);
+ expect(typeof Number()).toBe("number");
+ expect(typeof new Number()).toBe("object");
- assert(typeof Number() === "number");
- assert(typeof new Number() === "object");
-
- assert(Number() === 0);
- assert(new Number().valueOf() === 0);
- assert(Number("42") === 42);
- assert(new Number("42").valueOf() === 42);
- assert(Number(null) === 0);
- assert(new Number(null).valueOf() === 0);
- assert(Number(true) === 1);
- assert(new Number(true).valueOf() === 1);
- assert(Number("Infinity") === Infinity);
- assert(new Number("Infinity").valueOf() === Infinity);
- assert(Number("+Infinity") === Infinity);
- assert(new Number("+Infinity").valueOf() === Infinity);
- assert(Number("-Infinity") === -Infinity);
- assert(new Number("-Infinity").valueOf() === -Infinity);
- assert(isNaN(Number(undefined)));
- assert(isNaN(new Number(undefined).valueOf()));
- assert(isNaN(Number({})));
- assert(isNaN(new Number({}).valueOf()));
- assert(isNaN(Number({a: 1})));
- assert(isNaN(new Number({a: 1}).valueOf()));
- assert(isNaN(Number([1, 2, 3])));
- assert(isNaN(new Number([1, 2, 3]).valueOf()));
- assert(isNaN(Number("foo")));
- assert(isNaN(new Number("foo").valueOf()));
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e.message);
-}
+ expect(Number()).toBe(0);
+ expect(new Number().valueOf()).toBe(0);
+ expect(Number("42")).toBe(42);
+ expect(new Number("42").valueOf()).toBe(42);
+ expect(Number(null)).toBe(0);
+ expect(new Number(null).valueOf()).toBe(0);
+ expect(Number(true)).toBe(1);
+ expect(new Number(true).valueOf()).toBe(1);
+ expect(Number("Infinity")).toBe(Infinity);
+ expect(new Number("Infinity").valueOf()).toBe(Infinity);
+ expect(Number("+Infinity")).toBe(Infinity);
+ expect(new Number("+Infinity").valueOf()).toBe(Infinity);
+ expect(Number("-Infinity")).toBe(-Infinity);
+ expect(new Number("-Infinity").valueOf()).toBe(-Infinity);
+ expect(Number(undefined)).toBeNaN();
+ expect(new Number(undefined).valueOf()).toBeNaN();
+ expect(Number({})).toBeNaN();
+ expect(new Number({}).valueOf()).toBeNaN();
+ expect(Number({a: 1})).toBeNaN();
+ expect(new Number({a: 1}).valueOf()).toBeNaN();
+ expect(Number([1, 2, 3])).toBeNaN();
+ expect(new Number([1, 2, 3]).valueOf()).toBeNaN();
+ expect(Number("foo")).toBeNaN();
+ expect(new Number("foo").valueOf()).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js b/Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js
index e395e43602..89de9ff0d9 100644
--- a/Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js
+++ b/Libraries/LibJS/Tests/builtins/Number/Number.parseFloat.js
@@ -1,11 +1,5 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
// Ensuring it's the same function as the global
// parseFloat() is enough as that already has tests :^)
- assert(Number.parseFloat === parseFloat);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Number.parseFloat).toBe(parseFloat);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js b/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js
index f42f913fba..4c4f68b296 100644
--- a/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js
+++ b/Libraries/LibJS/Tests/builtins/Number/Number.prototype.js
@@ -1,10 +1,4 @@
-load("test-common.js");
-
-try {
- assert(typeof Number.prototype === "object");
- assert(Number.prototype.valueOf() === 0);
-
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+test("basic functionality", () => {
+ expect(typeof Number.prototype).toBe("object");
+ expect(Number.prototype.valueOf()).toBe(0);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js b/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js
index 2fce7a9835..0553623379 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.defineProperty.js
@@ -1,123 +1,127 @@
-load("test-common.js");
-
-try {
- var o = {};
- Object.defineProperty(o, "foo", { value: 1, writable: false, enumerable: false });
-
- assert(o.foo === 1);
- o.foo = 2;
- assert(o.foo === 1);
- Object.defineProperty(o, 2, { get() { return 10; } });
- assert(o[2] === 10);
-
- var d = Object.getOwnPropertyDescriptor(o, "foo");
- assert(d.configurable === false);
- assert(d.enumerable === false);
- assert(d.writable === false);
- assert(d.value === 1);
-
- Object.defineProperty(o, "bar", { value: "hi", writable: true, enumerable: true });
-
- assert(o.bar === "hi");
- o.bar = "ho";
- assert(o.bar === "ho");
-
- d = Object.getOwnPropertyDescriptor(o, "bar");
- assert(d.configurable === false);
- assert(d.enumerable === true);
- assert(d.writable === true);
- assert(d.value === "ho");
-
- assertThrowsError(() => {
- Object.defineProperty(o, "bar", { value: "xx", enumerable: false });
- }, {
- error: TypeError
+describe("normal functionality", () => {
+ test("non-configurable property", () => {
+ let o = {};
+ Object.defineProperty(o, "foo", { value: 1, writable: false, enumerable: false });
+
+ expect(o.foo).toBe(1);
+ o.foo = 2;
+ expect(o.foo).toBe(1);
+
+ expect(o).not.toHaveConfigurableProperty("foo");
+ expect(o).not.toHaveEnumerableProperty("foo");
+ expect(o).not.toHaveWritableProperty("foo");
+ expect(o).toHaveValueProperty("foo", 1);
});
- Object.defineProperty(o, "baz", { value: 9, configurable: true, writable: false });
- Object.defineProperty(o, "baz", { configurable: true, writable: true });
-
- d = Object.getOwnPropertyDescriptor(o, "baz");
- assert(d.configurable === true);
- assert(d.writable === true);
- assert(d.value === 9);
-
- Object.defineProperty(o, "qux", {
- configurable: true,
- get() {
- return o.secret_qux + 1;
- },
- set(value) {
- this.secret_qux = value + 1;
- },
+ test("array index getter", () => {
+ let o = {};
+ Object.defineProperty(o, 2, { get() { return 10; } });
+ expect(o[2]).toBe(10);
});
- o.qux = 10;
- assert(o.qux === 12);
- o.qux = 20;
- assert(o.qux = 22);
-
- Object.defineProperty(o, "qux", { configurable: true, value: 4 });
-
- assert(o.qux === 4);
- o.qux = 5;
- assert(o.qux = 4);
-
- Object.defineProperty(o, "qux", {
- configurable: false,
- get() {
- return this.secret_qux + 2;
- },
- set(value) {
- o.secret_qux = value + 2;
- },
+ test("configurable property", () => {
+ let o = {};
+ Object.defineProperty(o, "foo", { value: "hi", writable: true, enumerable: true });
+
+ expect(o.foo).toBe("hi");
+ o.foo = "ho";
+ expect(o.foo).toBe("ho");
+
+ expect(o).not.toHaveConfigurableProperty("foo");
+ expect(o).toHaveEnumerableProperty("foo");
+ expect(o).toHaveWritableProperty("foo");
+ expect(o).toHaveValueProperty("foo", "ho");
});
- o.qux = 10;
- assert(o.qux === 14);
- o.qux = 20;
- assert(o.qux = 24);
+ test("reconfigure configurable property", () => {
+ let o = {};
+ Object.defineProperty(o, "foo", { value: 9, configurable: true, writable: false });
+ Object.defineProperty(o, "foo", { configurable: true, writable: true });
- assertThrowsError(() => {
- Object.defineProperty(o, "qux", {
- configurable: false,
+ expect(o).toHaveConfigurableProperty("foo");
+ expect(o).toHaveWritableProperty("foo");
+ expect(o).not.toHaveEnumerableProperty("foo");
+ expect(o).toHaveValueProperty("foo", 9);
+ });
+
+ test("define accessor", () => {
+ let o = {};
+
+ Object.defineProperty(o, "foo", {
+ configurable: true,
get() {
- return this.secret_qux + 2;
+ return o.secret_foo + 1;
+ },
+ set(value) {
+ this.secret_foo = value + 1;
},
});
- }, {
- error: TypeError,
- message: "Cannot change attributes of non-configurable property 'qux'",
+
+ o.foo = 10;
+ expect(o.foo).toBe(12);
+ o.foo = 20;
+ expect(o.foo).toBe(22);
+
+ Object.defineProperty(o, "foo", { configurable: true, value: 4 });
+
+ expect(o.foo).toBe(4);
+ expect(o.foo = 5).toBe(5);
+ expect(o.foo = 4).toBe(4);
});
+});
+
+describe("errors", () => {
+ test("redefine non-configurable property", () => {
+ let o = {};
+ Object.defineProperty(o, "foo", { value: 1, writable: true, enumerable: true });
- assertThrowsError(() => {
- Object.defineProperty(o, "qux", { value: 2 });
- }, {
- error: TypeError,
- message: "Cannot change attributes of non-configurable property 'qux'",
+ expect(() => {
+ Object.defineProperty(o, "foo", { value: 2, writable: false, enumerable: true });
+ }).toThrowWithMessage(TypeError, "Cannot change attributes of non-configurable property 'foo'");
});
- assertThrowsError(() => {
- Object.defineProperty(o, "a", {
- get() {},
- value: 9,
- });
- }, {
- error: TypeError,
- message: "Accessor property descriptor cannot specify a value or writable key",
+ test("cannot define 'value' and 'get' in the same descriptor", () => {
+ let o = {};
+
+ expect(() => {
+ Object.defineProperty(o, "a", {
+ get() {},
+ value: 9,
+ });
+ }).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key");
});
- assertThrowsError(() => {
- Object.defineProperty(o, "a", {
- set() {},
- writable: true,
- });
- }, {
- error: TypeError,
- message: "Accessor property descriptor cannot specify a value or writable key",
+ test("cannot define 'value' and 'set' in the same descriptor", () => {
+ let o = {};
+
+ expect(() => {
+ Object.defineProperty(o, "a", {
+ set() {},
+ writable: true,
+ });
+ }).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key");
});
- console.log("PASS");
-} catch (e) {
- console.log(e)
-}
+ test("redefine non-configurable accessor", () => {
+ let o = {};
+
+ Object.defineProperty(o, "foo", {
+ configurable: false,
+ get() {
+ return this.secret_foo + 2;
+ },
+ set(value) {
+ o.secret_foo = value + 2;
+ },
+ });
+
+ expect(() => {
+ Object.defineProperty(o, "foo", {
+ configurable: false,
+ get() {
+ return this.secret_foo + 2;
+ },
+ });
+ }).toThrowWithMessage(TypeError, "Cannot change attributes of non-configurable property 'foo'");
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.entries.js b/Libraries/LibJS/Tests/builtins/Object/Object.entries.js
index d8786c52b6..11eb145308 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.entries.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.entries.js
@@ -1,54 +1,45 @@
-load("test-common.js");
+describe("basic functionality", () => {
+ test("length", () => {
+ expect(Object.entries).toHaveLength(1);
+ expect(Object.entries(true)).toHaveLength(0);
+ expect(Object.entries(45)).toHaveLength(0);
+ expect(Object.entries(-998)).toHaveLength(0);
+ expect(Object.entries("abcd")).toHaveLength(4);
+ expect(Object.entries([1, 2, 3])).toHaveLength(3);
+ expect(Object.entries({ a: 1, b: 2, c: 3 })).toHaveLength(3);
+ });
-try {
- assert(Object.entries.length === 1);
- assert(Object.entries(true).length === 0);
- assert(Object.entries(45).length === 0);
- assert(Object.entries(-998).length === 0);
- assert(Object.entries("abcd").length === 4);
- assert(Object.entries([1, 2, 3]).length === 3);
- assert(Object.entries({ a: 1, b: 2, c: 3 }).length === 3);
+ test("entries with object", () => {
+ let entries = Object.entries({ foo: 1, bar: 2, baz: 3 });
- assertThrowsError(() => {
- Object.entries(null);
- }, {
- error: TypeError,
- message: "ToObject on null or undefined",
+ expect(entries).toEqual([["foo", 1], ["bar", 2], ["baz", 3]]);
});
- assertThrowsError(() => {
- Object.entries(undefined);
- }, {
- error: TypeError,
- message: "ToObject on null or undefined",
+ test("entries with array", () => {
+ entries = Object.entries(["a", "b", "c"]);
+ expect(entries).toEqual([["0", "a"], ["1", "b"], ["2", "c"]]);
});
- let entries = Object.entries({ foo: 1, bar: 2, baz: 3 });
- assert(
- entries.length === 3 && entries[0].length === 2 &&
- entries[1].length === 2 && entries[2].length === 2 &&
- entries[0][0] === "foo" && entries[0][1] === 1 &&
- entries[1][0] === "bar" && entries[1][1] === 2 &&
- entries[2][0] === "baz" && entries[2][1] === 3
- );
-
- entries = Object.entries(["a", "b", "c"]);
- assert(
- entries.length === 3 && entries[0].length === 2 &&
- entries[1].length === 2 && entries[2].length === 2 &&
- entries[0][0] === "0" && entries[0][1] === "a" &&
- entries[1][0] === "1" && entries[1][1] === "b" &&
- entries[2][0] === "2" && entries[2][1] === "c"
- );
+ test("ignores non-enumerable properties", () => {
+ let obj = { foo: 1 };
+ Object.defineProperty(obj, "getFoo", {
+ value: function() { return this.foo; },
+ });
+ let entries = Object.entries(obj);
+ expect(entries).toEqual([["foo", 1]]);
+ });
+});
- let obj = { foo: 1 };
- Object.defineProperty(obj, "getFoo", {
- value: function() { return this.foo; },
+describe("errors", () => {
+ test("null argument", () => {
+ expect(() => {
+ Object.entries(null);
+ }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
- let entries = Object.entries(obj);
- assert(entries.length === 1 && entries[0][0] === "foo" && entries[0][1] === 1);
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ test("undefined argument", () => {
+ expect(() => {
+ Object.entries(undefined);
+ }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
+ })
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js
index a51af15ca5..a1783add2c 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js
@@ -1,51 +1,49 @@
-load("test-common.js");
+test("plain property", () => {
+ let o = { foo: "bar" };
-try {
- let o = {
- foo: "bar",
- get x() { },
- set ["hi" + 1](_) { },
- };
+ expect(o).toHaveConfigurableProperty("foo");
+ expect(o).toHaveEnumerableProperty("foo");
+ expect(o).toHaveWritableProperty("foo");
+ expect(o).toHaveValueProperty("foo", "bar");
+ expect(o).not.toHaveGetterProperty("foo");
+ expect(o).not.toHaveSetterProperty("foo");
+});
- Object.defineProperty(o, "baz", {
+test("getter property", () => {
+ let o = { get foo() {} };
+
+ expect(o).toHaveConfigurableProperty("foo");
+ expect(o).toHaveEnumerableProperty("foo");
+ expect(o).not.toHaveWritableProperty("foo");
+ expect(o).not.toHaveValueProperty("foo");
+ expect(o).toHaveGetterProperty("foo");
+ expect(o).not.toHaveSetterProperty("foo");
+});
+
+test("setter property", () => {
+ let o = { set foo(_) {} };
+
+ expect(o).toHaveConfigurableProperty("foo");
+ expect(o).toHaveEnumerableProperty("foo");
+ expect(o).not.toHaveWritableProperty("foo");
+ expect(o).not.toHaveValueProperty("foo");
+ expect(o).not.toHaveGetterProperty("foo");
+ expect(o).toHaveSetterProperty("foo");
+});
+
+test("defined property", () => {
+ let o = {};
+
+ Object.defineProperty(o, "foo", {
enumerable: false,
writable: true,
value: 10,
});
- let d = Object.getOwnPropertyDescriptor(o, "foo");
- assert(d.enumerable === true);
- assert(d.configurable === true);
- assert(d.writable === true);
- assert(d.value === "bar");
- assert(d.get === undefined);
- assert(d.set === undefined);
-
- let d = Object.getOwnPropertyDescriptor(o, "x");
- assert(d.enumerable === true);
- assert(d.configurable === true);
- assert(d.writable === undefined);
- assert(d.value === undefined);
- assert(typeof d.get === "function");
- assert(d.set === undefined);
-
- let d = Object.getOwnPropertyDescriptor(o, "hi1");
- assert(d.enumerable === true);
- assert(d.configurable === true);
- assert(d.writable === undefined);
- assert(d.value === undefined);
- assert(d.get === undefined);
- assert(typeof d.set === "function");
-
- let d = Object.getOwnPropertyDescriptor(o, "baz");
- assert(d.enumerable === false);
- assert(d.configurable === false);
- assert(d.writable === true);
- assert(d.value === 10);
- assert(d.get === undefined);
- assert(d.set === undefined);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(o).not.toHaveConfigurableProperty("foo");
+ expect(o).not.toHaveEnumerableProperty("foo");
+ expect(o).toHaveWritableProperty("foo");
+ expect(o).toHaveValueProperty("foo", 10);
+ expect(o).not.toHaveGetterProperty("foo");
+ expect(o).not.toHaveSetterProperty("foo");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js
index 72f77d6276..69ab0685df 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js
@@ -1,21 +1,9 @@
-load("test-common.js");
-
-try {
+test("use with array", () => {
let names = Object.getOwnPropertyNames([1, 2, 3]);
+ expect(names).toEqual(["0", "1", "2", "length"]);
+});
- assert(names.length === 4);
- assert(names[0] === "0");
- assert(names[1] === "1");
- assert(names[2] === "2");
- assert(names[3] === "length");
-
- names = Object.getOwnPropertyNames({ foo: 1, bar: 2, baz: 3 });
- assert(names.length === 3);
- assert(names[0] === "foo");
- assert(names[1] === "bar");
- assert(names[2] === "baz");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("use with object", () => {
+ let names = Object.getOwnPropertyNames({ foo: 1, bar: 2, baz: 3 });
+ expect(names).toEqual(["foo", "bar", "baz"]);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js
index 3e35fcb797..331ee5079f 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.getPrototypeOf.js
@@ -1,11 +1,10 @@
-load("test-common.js");
+test("basic functionality", () => {
+ let o1 = new Object();
+ let o2 = {};
-try {
- var o1 = new Object();
- var o2 = {};
- assert(Object.getPrototypeOf(o1) === Object.getPrototypeOf(o2));
- assert(Object.getPrototypeOf(Object.getPrototypeOf(o1)) === null);
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Object.getPrototypeOf(o1)).toBe(Object.getPrototypeOf(o2));
+ expect(Object.getPrototypeOf(Object.getPrototypeOf(o1))).toBe(null);
+
+ Object.setPrototypeOf(o1, o2);
+ expect(Object.getPrototypeOf(o1)).toBe(o2);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.is.js b/Libraries/LibJS/Tests/builtins/Object/Object.is.js
index e58d1ded22..9f748f65b8 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.is.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.is.js
@@ -1,53 +1,54 @@
-load("test-common.js");
+test("length", () => {
+ expect(Object.is).toHaveLength(2);
+});
-try {
- assert(Object.is.length === 2);
+test("arguments that evaluate to true", () => {
+ let a = [1, 2, 3];
+ let o = { foo: "bar" };
- var a = [1, 2, 3];
- var o = {foo: "bar"};
+ expect(Object.is("", "")).toBeTrue();
+ expect(Object.is("foo", "foo")).toBeTrue();
+ expect(Object.is(0, 0)).toBeTrue();
+ expect(Object.is(+0, +0)).toBeTrue();
+ expect(Object.is(-0, -0)).toBeTrue();
+ expect(Object.is(1.23, 1.23)).toBeTrue();
+ expect(Object.is(42, 42)).toBeTrue();
+ expect(Object.is(NaN, NaN)).toBeTrue();
+ expect(Object.is(Infinity, Infinity)).toBeTrue();
+ expect(Object.is(+Infinity, +Infinity)).toBeTrue();
+ expect(Object.is(-Infinity, -Infinity)).toBeTrue();
+ expect(Object.is(true, true)).toBeTrue();
+ expect(Object.is(false, false)).toBeTrue();
+ expect(Object.is(null, null)).toBeTrue();
+ expect(Object.is(undefined, undefined)).toBeTrue();
+ expect(Object.is(undefined)).toBeTrue();
+ expect(Object.is()).toBeTrue();
+ expect(Object.is(a, a)).toBeTrue();
+ expect(Object.is(o, o)).toBeTrue();
+});
- assert(Object.is("", "") === true);
- assert(Object.is("foo", "foo") === true);
- assert(Object.is(0, 0) === true);
- assert(Object.is(+0, +0) === true);
- assert(Object.is(-0, -0) === true);
- assert(Object.is(1.23, 1.23) === true);
- assert(Object.is(42, 42) === true);
- assert(Object.is(NaN, NaN) === true);
- assert(Object.is(Infinity, Infinity) === true);
- assert(Object.is(+Infinity, +Infinity) === true);
- assert(Object.is(-Infinity, -Infinity) === true);
- assert(Object.is(true, true) === true);
- assert(Object.is(false, false) === true);
- assert(Object.is(null, null) === true);
- assert(Object.is(undefined, undefined) === true);
- assert(Object.is(undefined) === true);
- assert(Object.is() === true);
- assert(Object.is(a, a) === true);
- assert(Object.is(o, o) === true);
+test("arguments that evaluate to false", () => {
+ let a = [1, 2, 3];
+ let o = { foo: "bar" };
- assert(Object.is("test") === false);
- assert(Object.is("foo", "bar") === false);
- assert(Object.is(1, "1") === false);
- assert(Object.is(+0, -0) === false);
- assert(Object.is(-0, +0) === false);
- assert(Object.is(42, 24) === false);
- assert(Object.is(Infinity, -Infinity) === false);
- assert(Object.is(-Infinity, +Infinity) === false);
- assert(Object.is(true, false) === false);
- assert(Object.is(false, true) === false);
- assert(Object.is(undefined, null) === false);
- assert(Object.is(null, undefined) === false);
- assert(Object.is([], []) === false);
- assert(Object.is(a, [1, 2, 3]) === false);
- assert(Object.is([1, 2, 3], a) === false);
- assert(Object.is({}, {}) === false);
- assert(Object.is(o, {foo: "bar"}) === false);
- assert(Object.is({foo: "bar"}, o) === false);
- assert(Object.is(a, o) === false);
- assert(Object.is(o, a) === false);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Object.is("test")).toBeFalse();
+ expect(Object.is("foo", "bar")).toBeFalse();
+ expect(Object.is(1, "1")).toBeFalse();
+ expect(Object.is(+0, -0)).toBeFalse();
+ expect(Object.is(-0, +0)).toBeFalse();
+ expect(Object.is(42, 24)).toBeFalse();
+ expect(Object.is(Infinity, -Infinity)).toBeFalse();
+ expect(Object.is(-Infinity, +Infinity)).toBeFalse();
+ expect(Object.is(true, false)).toBeFalse();
+ expect(Object.is(false, true)).toBeFalse();
+ expect(Object.is(undefined, null)).toBeFalse();
+ expect(Object.is(null, undefined)).toBeFalse();
+ expect(Object.is([], [])).toBeFalse();
+ expect(Object.is(a, [1, 2, 3])).toBeFalse();
+ expect(Object.is([1, 2, 3], a)).toBeFalse();
+ expect(Object.is({}, {})).toBeFalse();
+ expect(Object.is(o, {foo: "bar"})).toBeFalse();
+ expect(Object.is({foo: "bar"}, o)).toBeFalse();
+ expect(Object.is(a, o)).toBeFalse();
+ expect(Object.is(o, a)).toBeFalse();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js b/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js
index a8870da53d..b426114f20 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.isExtensible.js
@@ -1,22 +1,18 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Object.isExtensible).toHaveLength(1);
-try {
- assert(Object.isExtensible() === false);
- assert(Object.isExtensible(undefined) === false);
- assert(Object.isExtensible(null) === false);
- assert(Object.isExtensible(true) === false);
- assert(Object.isExtensible(6) === false);
- assert(Object.isExtensible("test") === false);
+ expect(Object.isExtensible()).toBeFalse();
+ expect(Object.isExtensible(undefined)).toBeFalse();
+ expect(Object.isExtensible(null)).toBeFalse();
+ expect(Object.isExtensible(true)).toBeFalse();
+ expect(Object.isExtensible(6)).toBeFalse();
+ expect(Object.isExtensible("test")).toBeFalse();
let s = Symbol();
- assert(Object.isExtensible(s) === false);
+ expect(Object.isExtensible(s)).toBeFalse();
let o = { foo: "foo" };
- assert(Object.isExtensible(o) === true);
+ expect(Object.isExtensible(o)).toBeTrue();
Object.preventExtensions(o);
- assert(Object.isExtensible(o) === false);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Object.isExtensible(o)).toBeFalse();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.js b/Libraries/LibJS/Tests/builtins/Object/Object.js
index b51e0a4abf..0b4ed04b50 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.js
@@ -1,14 +1,8 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(Object).toHaveLength(1);
+ expect(Object.name).toBe("Object");
+ expect(Object.prototype.length).toBe(undefined);
-try {
- assert(Object.length === 1);
- assert(Object.name === "Object");
- assert(Object.prototype.length === undefined);
-
- assert(typeof Object() === "object");
- assert(typeof new Object() === "object");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(typeof Object()).toBe("object");
+ expect(typeof new Object()).toBe("object");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.keys.js b/Libraries/LibJS/Tests/builtins/Object/Object.keys.js
index 14e5597e53..620d7af97d 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.keys.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.keys.js
@@ -1,42 +1,44 @@
-load("test-common.js");
-
-try {
- assert(Object.keys.length === 1);
- assert(Object.keys(true).length === 0);
- assert(Object.keys(45).length === 0);
- assert(Object.keys(-998).length === 0);
- assert(Object.keys("abcd").length === 4);
- assert(Object.keys([1, 2, 3]).length === 3);
- assert(Object.keys({ a: 1, b: 2, c: 3 }).length === 3);
-
- assertThrowsError(() => {
- Object.keys(null);
- }, {
- error: TypeError,
- message: "ToObject on null or undefined",
+describe("correct behavior", () => {
+ test("length", () => {
+ expect(Object.keys).toHaveLength(1);
+ expect(Object.keys(true)).toHaveLength(0);
+ expect(Object.keys(45)).toHaveLength(0);
+ expect(Object.keys(-998)).toHaveLength(0);
+ expect(Object.keys("abcd")).toHaveLength(4);
+ expect(Object.keys([1, 2, 3])).toHaveLength(3);
+ expect(Object.keys({ a: 1, b: 2, c: 3 })).toHaveLength(3);
});
- assertThrowsError(() => {
- Object.keys(undefined);
- }, {
- error: TypeError,
- message: "ToObject on null or undefined",
+ test("object argument", () => {
+ let keys = Object.keys({ foo: 1, bar: 2, baz: 3 });
+ expect(keys).toEqual(["foo", "bar", "baz"]);
});
- let keys = Object.keys({ foo: 1, bar: 2, baz: 3 });
- assert(keys[0] === "foo" && keys[1] === "bar" && keys[2] === "baz");
+ test("array argument", () => {
+ let keys = Object.keys(["a", "b", "c"]);
+ expect(keys).toEqual(["0", "1", "2"]);
+ });
- keys = Object.keys(["a", "b", "c"]);
- assert(keys[0] === "0" && keys[1] === "1" && keys[2] === "2");
+ test("ignores non-enumerable properties", () => {
+ let obj = { foo: 1 };
+ Object.defineProperty(obj, "getFoo", {
+ value: function() { return this.foo; },
+ });
+ keys = Object.keys(obj);
+ expect(keys).toEqual(["foo"]);
+ });
+});
- let obj = { foo: 1 };
- Object.defineProperty(obj, 'getFoo', {
- value: function() { return this.foo; },
+describe("errors", () => {
+ test("null argument value", () => {
+ expect(() => {
+ Object.keys(null);
+ }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
- keys = Object.keys(obj);
- assert(keys.length === 1 && keys[0] === 'foo');
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ test("undefined argument value", () => {
+ expect(() => {
+ Object.keys(undefined);
+ }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js b/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js
index c22cc22a2e..6752c1b19a 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.preventExtensions.js
@@ -1,54 +1,53 @@
-load("test-common.js");
-
-try {
- assert(Object.preventExtensions() === undefined);
- assert(Object.preventExtensions(undefined) === undefined);
- assert(Object.preventExtensions(null) === null);
- assert(Object.preventExtensions(true) === true);
- assert(Object.preventExtensions(6) === 6);
- assert(Object.preventExtensions("test") === "test");
-
- let s = Symbol();
- assert(Object.preventExtensions(s) === s);
-
- let o = { foo: "foo" };
- assert(o.foo === "foo");
- o.bar = "bar";
- assert(o.bar === "bar");
-
- assert(Object.preventExtensions(o) === o);
- assert(o.foo === "foo");
- assert(o.bar === "bar");
-
- o.baz = "baz";
- assert(o.baz === undefined);
-
- assertThrowsError(() => {
- Object.defineProperty(o, "baz", { value: "baz" });
- }, {
- error: TypeError,
- message: "Cannot define property baz on non-extensible object",
+describe("correct behavior", () => {
+ test("non-object arguments", () => {
+ expect(Object.preventExtensions()).toBeUndefined();
+ expect(Object.preventExtensions(undefined)).toBeUndefined();
+ expect(Object.preventExtensions(null)).toBeNull();
+ expect(Object.preventExtensions(true)).toBeTrue();
+ expect(Object.preventExtensions(6)).toBe(6);
+ expect(Object.preventExtensions("test")).toBe("test");
+
+ let s = Symbol();
+ expect(Object.preventExtensions(s)).toBe(s);
});
- assert(o.baz === undefined);
+ test("basic functionality", () => {
+ let o = { foo: "foo" };
+ expect(o.foo).toBe("foo");
+ o.bar = "bar";
+ expect(o.bar).toBe("bar");
+
+ expect(Object.preventExtensions(o)).toBe(o);
+ expect(o.foo).toBe("foo");
+ expect(o.bar).toBe("bar");
- assertThrowsError(() => {
- "use strict";
o.baz = "baz";
- }, {
- error: TypeError,
- message: "Cannot define property baz on non-extensible object",
+ expect(o.baz).toBeUndefined();
});
+});
+
+describe("errors", () => {
+ test("defining a property on a non-extensible object", () => {
+ let o = {};
+ Object.preventExtensions(o);
+
+ expect(() => {
+ Object.defineProperty(o, "baz", { value: "baz" });
+ }).toThrowWithMessage(TypeError, "Cannot define property baz on non-extensible object");
- assertThrowsError(() => {
- "use strict";
- Object.defineProperty(o, "baz", { value: "baz" });
- }, {
- error: TypeError,
- message: "Cannot define property baz on non-extensible object",
+ expect(o.baz).toBeUndefined();
});
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ test("putting property on a non-extensible object", () => {
+ let o = {};
+ Object.preventExtensions(o);
+
+ expect(() => {
+ "use strict";
+ o.foo = "foo";
+ }).toThrowWithMessage(TypeError, "Cannot define property foo on non-extensible object");
+
+ expect(o.foo = "foo").toBe("foo");
+ expect(o.foo).toBeUndefined();
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js
index ff862fae05..50e4935c75 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.constructor.js
@@ -1,36 +1,18 @@
-load("test-common.js");
+test("basic functionality", () => {
+ [Array, BigInt, Boolean, Date, Error, Function, Number, Object, String].forEach(constructor => {
+ expect(constructor.prototype.constructor).toBe(constructor);
+ if (constructor !== BigInt)
+ expect(Reflect.construct(constructor, []).constructor).toBe(constructor);
+ });
-try {
- assert(Array.prototype.constructor === Array);
- assert(Boolean.prototype.constructor === Boolean);
- assert(Date.prototype.constructor === Date);
- assert(Error.prototype.constructor === Error);
- assert(Function.prototype.constructor === Function);
- assert(Number.prototype.constructor === Number);
- assert(Object.prototype.constructor === Object);
-
- o = {};
- assert(o.constructor === Object);
-
- o = new Object();
- assert(o.constructor === Object);
+ let o = {};
+ expect(o.constructor).toBe(Object);
a = [];
- assert(a.constructor === Array);
-
- a = new Array();
- assert(a.constructor === Array);
-
- n = new Number(3);
- assert(n.constructor === Number);
-
- d = Object.getOwnPropertyDescriptor(Object.prototype, "constructor");
- assert(d.configurable === true);
- assert(d.enumerable === false);
- assert(d.writable === true);
- assert(d.value === Object);
+ expect(a.constructor).toBe(Array);
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Object.prototype).toHaveConfigurableProperty("constructor");
+ expect(Object.prototype).not.toHaveEnumerableProperty("constructor");
+ expect(Object.prototype).toHaveWritableProperty("constructor");
+ expect(Object.prototype).toHaveValueProperty("constructor", Object);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js
index 16dec1062c..11063f42ec 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.hasOwnProperty.js
@@ -1,17 +1,13 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var o = {};
+
o.foo = 1;
- assert(o.hasOwnProperty("foo") === true);
- assert(o.hasOwnProperty("bar") === false);
- assert(o.hasOwnProperty() === false);
- assert(o.hasOwnProperty(undefined) === false);
- o.undefined = 2;
- assert(o.hasOwnProperty() === true);
- assert(o.hasOwnProperty(undefined) === true);
+ expect(o.hasOwnProperty("foo")).toBeTrue();
+ expect(o.hasOwnProperty("bar")).toBeFalse();
+ expect(o.hasOwnProperty()).toBeFalse();
+ expect(o.hasOwnProperty(undefined)).toBeFalse();
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ o.undefined = 2;
+ expect(o.hasOwnProperty()).toBeTrue();
+ expect(o.hasOwnProperty(undefined)).toBeTrue();
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js
index 549716bb65..eab7093b3b 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.js
@@ -1,10 +1,5 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
var o = new Object();
Object.prototype.foo = 123;
- assert(o.foo === 123);
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(o.foo).toBe(123);
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js
index 2868548376..ee5ccd2fad 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toLocaleString.js
@@ -1,32 +1,31 @@
-load("test-common.js");
+describe("correct behavior", () => {
+ test("length", () => {
+ expect(Object.prototype.toLocaleString).toHaveLength(0);
+ })
-try {
- assert(Object.prototype.toLocaleString.length === 0);
+ test("basic functionality", () => {
+ let o;
- var o;
+ o = {};
+ expect(o.toString()).toBe(o.toLocaleString());
- o = {};
- assert(o.toString() === o.toLocaleString());
-
- o = { toString: () => 42 };
- assert(o.toString() === 42);
-
- o = { toString: () => { throw Error(); } };
- assertThrowsError(() => {
- o.toLocaleString();
- }, {
- error: Error
+ o = { toString: () => 42 };
+ expect(o.toString()).toBe(42);
});
+});
- o = { toString: "foo" };
- assertThrowsError(() => {
- o.toLocaleString();
- }, {
- error: TypeError,
- message: "foo is not a function"
+describe("errors", () => {
+ test("toString that throws error", () => {
+ let o = { toString: () => { throw new Error(); } };
+ expect(() => {
+ o.toLocaleString();
+ }).toThrow(Error);
});
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ test("toString that is not a function", () => {
+ let o = { toString: "foo" };
+ expect(() => {
+ o.toLocaleString();
+ }).toThrowWithMessage(TypeError, "foo is not a function");
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js
index 94b9c1f2b2..95001ed3f6 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js
@@ -1,8 +1,8 @@
-load("test-common.js");
-
-try {
- assert(typeof Object.prototype.toString() === "string");
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("basic functionality", () => {
+ expect(Object.prototype.toString).toHaveLength(0);
+ // FIXME: The tag is ObjectPrototype, but should be Object
+ // expect(Object.prototype.toString()).toBe("[object Object]");
+ expect({ foo: 1 }.toString()).toBe("[object Object]");
+ expect([].toString()).toBe("");
+ expect(Object.prototype.toString.call([])).toBe("[object Array]");
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js
index dca2118545..69a7b24ab3 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.setPrototypeOf.js
@@ -1,36 +1,43 @@
-load("test-common.js");
+describe("correct behavior", () => {
+ test("length", () => {
+ expect(Object.setPrototypeOf).toHaveLength(2);
+ });
+
+ test("basic functionality", () => {
+ let o = {};
+ let p = {};
+ expect(Object.setPrototypeOf(o, p)).toBe(o);
+ expect(Object.getPrototypeOf(o)).toBe(p);
+ });
+});
-try {
- assert(Object.setPrototypeOf.length === 2);
+describe("errors", () => {
+ test("requires two arguments", () => {
+ expect(() => {
+ Object.setPrototypeOf();
+ }).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments");
- assertThrowsError(() => {
- Object.setPrototypeOf();
- }, {
- error: TypeError,
- message: "Object.setPrototypeOf requires at least two arguments",
+ expect(() => {
+ Object.setPrototypeOf({});
+ }).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments");
});
- assertThrowsError(() => {
- Object.setPrototypeOf({}, "foo");
- }, {
- error: TypeError,
- message: "Prototype must be an object or null"
+ test("prototype must be an object", () => {
+ expect(() => {
+ Object.setPrototypeOf({}, "foo");
+ }).toThrowWithMessage(TypeError, "Prototype must be an object or null");
});
- o = {};
- p = {};
- assert(Object.setPrototypeOf(o, p) === o);
+ test("non-extensible target", () => {
+ let o = {};
+ let p = {};
+ Object.setPrototypeOf(o, p);
+ Object.preventExtensions(o);
- Object.preventExtensions(o);
- assertThrowsError(() => {
- Object.setPrototypeOf(o, {});
- }, {
- error: TypeError,
- message: "Object's [[SetPrototypeOf]] method returned false"
- });
- assert(Object.setPrototypeOf(o, p) === o);
+ expect(() => {
+ Object.setPrototypeOf(o, {});
+ }).toThrowWithMessage(TypeError, "Object's [[SetPrototypeOf]] method returned false");
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(Object.setPrototypeOf(o, p)).toBe(o);
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.values.js b/Libraries/LibJS/Tests/builtins/Object/Object.values.js
index 5a360eb70c..da3e3a635c 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.values.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.values.js
@@ -1,42 +1,44 @@
-load("test-common.js");
-
-try {
- assert(Object.values.length === 1);
- assert(Object.values(true).length === 0);
- assert(Object.values(45).length === 0);
- assert(Object.values(-998).length === 0);
- assert(Object.values("abcd").length === 4);
- assert(Object.values([1, 2, 3]).length === 3);
- assert(Object.values({ a: 1, b: 2, c: 3 }).length === 3);
-
- assertThrowsError(() => {
- Object.values(null);
- }, {
- error: TypeError,
- message: "ToObject on null or undefined",
+describe("correct behavior", () => {
+ test("lengths", () => {
+ expect(Object.values).toHaveLength(1);
+ expect(Object.values(true)).toHaveLength(0);
+ expect(Object.values(45)).toHaveLength(0);
+ expect(Object.values(-998)).toHaveLength(0);
+ expect(Object.values("abcd")).toHaveLength(4);
+ expect(Object.values([1, 2, 3])).toHaveLength(3);
+ expect(Object.values({ a: 1, b: 2, c: 3 })).toHaveLength(3);
});
- assertThrowsError(() => {
- Object.values(undefined);
- }, {
- error: TypeError,
- message: "ToObject on null or undefined",
+ test("object argument", () => {
+ let values = Object.values({ foo: 1, bar: 2, baz: 3 });
+ expect(values).toEqual([1, 2, 3]);
});
- let values = Object.values({ foo: 1, bar: 2, baz: 3 });
- assert(values[0] === 1 && values[1] === 2 && values[2] === 3);
+ test("array argument", () => {
+ let values = Object.values(["a", "b", "c"]);
+ expect(values).toEqual(["a", "b", "c"]);
+ });
- values = Object.values(["a", "b", "c"]);
- assert(values[0] === "a" && values[1] === "b" && values[2] === "c");
+ test("ignores non-enumerable properties", () => {
+ let obj = { foo: 1 };
+ Object.defineProperty(obj, 'getFoo', {
+ value: function() { return this.foo; },
+ });
+ let values = Object.values(obj);
+ expect(values).toEqual([1]);
+ });
+});
- let obj = { foo: 1 };
- Object.defineProperty(obj, 'getFoo', {
- value: function() { return this.foo; },
+describe("errors", () => {
+ test("null argument", () => {
+ expect(() => {
+ Object.values(null);
+ }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
- let values = Object.values(obj);
- assert(values.length === 1 && values[0] === 1);
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ test("undefined argument", () => {
+ expect(() => {
+ Object.values(undefined);
+ }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
+ });
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js b/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js
index 3273209292..c6b52fd2e1 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.fromCharCode.js
@@ -1,23 +1,17 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.fromCharCode).toHaveLength(1);
-try {
- assert(String.fromCharCode.length === 1);
-
- assert(String.fromCharCode() === "");
- assert(String.fromCharCode(0) === "\u0000");
- assert(String.fromCharCode(false) === "\u0000");
- assert(String.fromCharCode(null) === "\u0000");
- assert(String.fromCharCode(undefined) === "\u0000");
- assert(String.fromCharCode(1) === "\u0001");
- assert(String.fromCharCode(true) === "\u0001");
- assert(String.fromCharCode(-1) === "\uffff");
- assert(String.fromCharCode(0xffff) === "\uffff");
- assert(String.fromCharCode(0x123ffff) === "\uffff");
- assert(String.fromCharCode(65) === "A");
- assert(String.fromCharCode(65, 66, 67) === "ABC");
- assert(String.fromCharCode(228, 246, 252) === "äöü");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(String.fromCharCode()).toBe("");
+ expect(String.fromCharCode(0)).toBe("\u0000");
+ expect(String.fromCharCode(false)).toBe("\u0000");
+ expect(String.fromCharCode(null)).toBe("\u0000");
+ expect(String.fromCharCode(undefined)).toBe("\u0000");
+ expect(String.fromCharCode(1)).toBe("\u0001");
+ expect(String.fromCharCode(true)).toBe("\u0001");
+ expect(String.fromCharCode(-1)).toBe("\uffff");
+ expect(String.fromCharCode(0xffff)).toBe("\uffff");
+ expect(String.fromCharCode(0x123ffff)).toBe("\uffff");
+ expect(String.fromCharCode(65)).toBe("A");
+ expect(String.fromCharCode(65, 66, 67)).toBe("ABC");
+ expect(String.fromCharCode(228, 246, 252)).toBe("äöü");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.js b/Libraries/LibJS/Tests/builtins/String/String.js
index 38ccccfb29..687e0929d4 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.js
@@ -1,23 +1,9 @@
-load("test-common.js");
-
-try {
- assert(String.length === 1);
- assert(String.name === "String");
- assert(String.prototype.length === 0);
-
- assert(typeof String() === "string");
- assert(typeof new String() === "object");
-
- assert(String() === "");
- assert(new String().valueOf() === "");
- assert(String("foo") === "foo");
- assert(new String("foo").valueOf() === "foo");
- assert(String(123) === "123");
- assert(new String(123).valueOf() === "123");
- assert(String(123) === "123");
- assert(new String(123).valueOf() === "123");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("constructor properties", () => {
+ expect(String).toHaveLength(1);
+ expect(String.name).toBe("String");
+});
+
+test("typeof", () => {
+ expect(typeof String()).toBe("string");
+ expect(typeof new String()).toBe("object");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js b/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js
index 2975f84a9c..3d7d7468b6 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js
@@ -1,6 +1,4 @@
-load("test-common.js");
-
-try {
+test("basic functionality", () => {
const genericStringPrototypeFunctions = [
"charAt",
"repeat",
@@ -24,29 +22,16 @@ try {
String.prototype[name].call({ toString: () => 123 });
String.prototype[name].call({ toString: () => undefined });
- assertThrowsError(() => {
+ expect(() => {
String.prototype[name].call({ toString: () => new String() });
- }, {
- error: TypeError,
- message: "Cannot convert object to string"
- });
+ }).toThrowWithMessage(TypeError, "Cannot convert object to string");
- assertThrowsError(() => {
+ expect(() => {
String.prototype[name].call({ toString: () => [] });
- }, {
- error: TypeError,
- message: "Cannot convert object to string"
- });
+ }).toThrowWithMessage(TypeError, "Cannot convert object to string");
- assertThrowsError(() => {
+ expect(() => {
String.prototype[name].call({ toString: () => ({}) });
- }, {
- error: TypeError,
- message: "Cannot convert object to string"
- });
+ }).toThrowWithMessage(TypeError, "Cannot convert object to string");
});
-
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js
index 234d388003..7f5ec19e83 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.charAt.js
@@ -1,24 +1,20 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.charAt).toHaveLength(1);
-try {
var s = "foobar"
- assert(typeof s === "string");
- assert(s.length === 6);
+ expect(typeof s).toBe("string");
+ expect(s).toHaveLength(6);
- assert(s.charAt(0) === 'f');
- assert(s.charAt(1) === 'o');
- assert(s.charAt(2) === 'o');
- assert(s.charAt(3) === 'b');
- assert(s.charAt(4) === 'a');
- assert(s.charAt(5) === 'r');
- assert(s.charAt(6) === '');
+ expect(s.charAt(0)).toBe("f");
+ expect(s.charAt(1)).toBe("o");
+ expect(s.charAt(2)).toBe("o");
+ expect(s.charAt(3)).toBe("b");
+ expect(s.charAt(4)).toBe("a");
+ expect(s.charAt(5)).toBe("r");
+ expect(s.charAt(6)).toBe("");
- assert(s.charAt() === 'f');
- assert(s.charAt(NaN) === 'f');
- assert(s.charAt("foo") === 'f');
- assert(s.charAt(undefined) === 'f');
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(s.charAt()).toBe("f");
+ expect(s.charAt(NaN)).toBe("f");
+ expect(s.charAt("foo")).toBe("f");
+ expect(s.charAt(undefined)).toBe("f");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js
index aee254ba71..4faab2a44f 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js
@@ -1,22 +1,17 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.concat).toHaveLength(1);
-try {
- assert(String.prototype.concat.length === 1);
- assert("".concat(1) === "1");
- assert("".concat(3,2,1) === "321");
- assert("hello".concat(" ", "friends") === "hello friends");
- assert("".concat(null) === "null");
- assert("".concat(false) === "false");
- assert("".concat(true) === "true");
- assert("".concat([]) === "");
- assert("".concat([1, 2, 3, 'hello']) === "1,2,3,hello");
- assert("".concat(true, []) === "true");
- assert("".concat(true, false) === "truefalse");
- assert("".concat({}) === "[object Object]");
- assert("".concat(1, {}) === "1[object Object]");
- assert("".concat(1, {}, false) === "1[object Object]false");
-
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+ expect("".concat(1)).toBe("1");
+ expect("".concat(3,2,1)).toBe("321");
+ expect("hello".concat(" ", "friends")).toBe("hello friends");
+ expect("".concat(null)).toBe("null");
+ expect("".concat(false)).toBe("false");
+ expect("".concat(true)).toBe("true");
+ expect("".concat([])).toBe("");
+ expect("".concat([1, 2, 3, 'hello'])).toBe("1,2,3,hello");
+ expect("".concat(true, [])).toBe("true");
+ expect("".concat(true, false)).toBe("truefalse");
+ expect("".concat({})).toBe("[object Object]");
+ expect("".concat(1, {})).toBe("1[object Object]");
+ expect("".concat(1, {}, false)).toBe("1[object Object]false");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js
index 70da3e7f12..e871e29ac7 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.includes.js
@@ -1,18 +1,12 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.includes).toHaveLength(1);
-try {
- assert(String.prototype.includes.length === 1);
-
- assert("hello friends".includes("hello") === true);
- assert("hello friends".includes("hello", 100) === false);
- assert("hello friends".includes("hello", -10) === true);
- assert("hello friends".includes("friends", 6) === true);
- assert("hello friends".includes("hello", 6) === false);
- assert("hello friends false".includes(false) === true);
- assert("hello 10 friends".includes(10) === true);
- assert("hello friends undefined".includes() === true);
-
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+ expect("hello friends".includes("hello")).toBe(true);
+ expect("hello friends".includes("hello", 100)).toBe(false);
+ expect("hello friends".includes("hello", -10)).toBe(true);
+ expect("hello friends".includes("friends", 6)).toBe(true);
+ expect("hello friends".includes("hello", 6)).toBe(false);
+ expect("hello friends false".includes(false)).toBe(true);
+ expect("hello 10 friends".includes(10)).toBe(true);
+ expect("hello friends undefined".includes()).toBe(true);
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js
index b0488e955c..289267b4a8 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.indexOf.js
@@ -1,12 +1,8 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.indexOf).toHaveLength(1);
-try {
var s = "hello friends"
- assert(s.indexOf("friends") === 6);
- assert(s.indexOf("enemies") === -1);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(s.indexOf("friends")).toBe(6);
+ expect(s.indexOf("enemies")).toBe(-1);
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.js
index a3b0228224..c9d41e4982 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.js
@@ -1,13 +1,9 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype).toHaveLength(0);
+
+ expect(typeof Object.getPrototypeOf("")).toBe("object");
+ expect(Object.getPrototypeOf("").valueOf()).toBe("");
-try {
- assert(typeof Object.getPrototypeOf("") === "object");
- assert(Object.getPrototypeOf("").valueOf() === '');
-
- assert(typeof String.prototype === "object");
- assert(String.prototype.valueOf() === '');
-
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+ expect(typeof String.prototype).toBe("object");
+ expect(String.prototype.valueOf()).toBe("");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js
index dbd72147d7..ce69fc3214 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.lastIndexOf.js
@@ -1,27 +1,22 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.lastIndexOf).toHaveLength(1);
-try {
- assert(String.prototype.lastIndexOf.length === 1);
- assert("hello friends".lastIndexOf() === -1);
- assert("hello friends".lastIndexOf("e") === 9);
- assert("hello friends".lastIndexOf("e", -7) === -1);
- assert("hello friends".lastIndexOf("e", 100) === 9);
- assert("hello friends".lastIndexOf("") === 13);
- assert("hello friends".lastIndexOf("Z") === -1);
- assert("hello friends".lastIndexOf("serenity") === -1);
- assert("hello friends".lastIndexOf("", 4) === 4);
- assert("hello serenity friends".lastIndexOf("serenity") === 6);
- assert("hello serenity friends serenity".lastIndexOf("serenity") === 23);
- assert("hello serenity friends serenity".lastIndexOf("serenity", 14) === 6);
- assert("".lastIndexOf("") === 0);
- assert("".lastIndexOf("", 1) === 0);
- assert("".lastIndexOf("", -1) === 0);
- assert("hello friends serenity".lastIndexOf("h", 10) === 0);
- assert("hello friends serenity".lastIndexOf("l", 4) === 3);
- assert("hello friends serenity".lastIndexOf("s", 13) === 12);
- assert("hello".lastIndexOf("serenity") === -1);
-
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+ expect("hello friends".lastIndexOf()).toBe(-1);
+ expect("hello friends".lastIndexOf("e")).toBe(9);
+ expect("hello friends".lastIndexOf("e", -7)).toBe(-1);
+ expect("hello friends".lastIndexOf("e", 100)).toBe(9);
+ expect("hello friends".lastIndexOf("")).toBe(13);
+ expect("hello friends".lastIndexOf("Z")).toBe(-1);
+ expect("hello friends".lastIndexOf("serenity")).toBe(-1);
+ expect("hello friends".lastIndexOf("", 4)).toBe(4);
+ expect("hello serenity friends".lastIndexOf("serenity")).toBe(6);
+ expect("hello serenity friends serenity".lastIndexOf("serenity")).toBe(23);
+ expect("hello serenity friends serenity".lastIndexOf("serenity", 14)).toBe(6);
+ expect("".lastIndexOf("")).toBe(0);
+ expect("".lastIndexOf("", 1)).toBe(0);
+ expect("".lastIndexOf("", -1)).toBe(0);
+ expect("hello friends serenity".lastIndexOf("h", 10)).toBe(0);
+ expect("hello friends serenity".lastIndexOf("l", 4)).toBe(3);
+ expect("hello friends serenity".lastIndexOf("s", 13)).toBe(12);
+ expect("hello".lastIndexOf("serenity")).toBe(-1);
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js
index 18ea5377cd..a103084c3a 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.padEnd.js
@@ -1,24 +1,18 @@
-load("test-common.js");
-
-try {
- assert(String.prototype.padEnd.length === 1);
+test("basic functionality", () => {
+ expect(String.prototype.padEnd).toHaveLength(1);
var s = "foo";
- assert(s.padEnd(-1) === "foo");
- assert(s.padEnd(0) === "foo");
- assert(s.padEnd(3) === "foo");
- assert(s.padEnd(5) === "foo ");
- assert(s.padEnd(10) === "foo ");
- assert(s.padEnd("5") === "foo ");
- assert(s.padEnd([[["5"]]]) === "foo ");
- assert(s.padEnd(2, "+") === "foo");
- assert(s.padEnd(5, "+") === "foo++");
- assert(s.padEnd(5, 1) === "foo11");
- assert(s.padEnd(10, null) === "foonullnul");
- assert(s.padEnd(10, "bar") === "foobarbarb");
- assert(s.padEnd(10, "123456789") === "foo1234567");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(s.padEnd(-1)).toBe("foo");
+ expect(s.padEnd(0)).toBe("foo");
+ expect(s.padEnd(3)).toBe("foo");
+ expect(s.padEnd(5)).toBe("foo ");
+ expect(s.padEnd(10)).toBe("foo ");
+ expect(s.padEnd("5")).toBe("foo ");
+ expect(s.padEnd([[["5"]]])).toBe("foo ");
+ expect(s.padEnd(2, "+")).toBe("foo");
+ expect(s.padEnd(5, "+")).toBe("foo++");
+ expect(s.padEnd(5, 1)).toBe("foo11");
+ expect(s.padEnd(10, null)).toBe("foonullnul");
+ expect(s.padEnd(10, "bar")).toBe("foobarbarb");
+ expect(s.padEnd(10, "123456789")).toBe("foo1234567");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js
index 0b2b99d803..a2f0f0b710 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.padStart.js
@@ -1,24 +1,18 @@
-load("test-common.js");
-
-try {
- assert(String.prototype.padStart.length === 1);
+test("basic functionality", () => {
+ expect(String.prototype.padStart).toHaveLength(1);
var s = "foo";
- assert(s.padStart(-1) === "foo");
- assert(s.padStart(0) === "foo");
- assert(s.padStart(3) === "foo");
- assert(s.padStart(5) === " foo");
- assert(s.padStart(10) === " foo");
- assert(s.padStart("5") === " foo");
- assert(s.padStart([[["5"]]]) === " foo");
- assert(s.padStart(2, "+") === "foo");
- assert(s.padStart(5, "+") === "++foo");
- assert(s.padStart(5, 1) === "11foo");
- assert(s.padStart(10, null) === "nullnulfoo");
- assert(s.padStart(10, "bar") === "barbarbfoo");
- assert(s.padStart(10, "123456789") === "1234567foo");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(s.padStart(-1)).toBe("foo");
+ expect(s.padStart(0)).toBe("foo");
+ expect(s.padStart(3)).toBe("foo");
+ expect(s.padStart(5)).toBe(" foo");
+ expect(s.padStart(10)).toBe(" foo");
+ expect(s.padStart("5")).toBe(" foo");
+ expect(s.padStart([[["5"]]])).toBe(" foo");
+ expect(s.padStart(2, "+")).toBe("foo");
+ expect(s.padStart(5, "+")).toBe("++foo");
+ expect(s.padStart(5, 1)).toBe("11foo");
+ expect(s.padStart(10, null)).toBe("nullnulfoo");
+ expect(s.padStart(10, "bar")).toBe("barbarbfoo");
+ expect(s.padStart(10, "123456789")).toBe("1234567foo");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js
index 3b711a0f7b..8427698509 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js
@@ -1,37 +1,25 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.repeat).toHaveLength(1);
-try {
- assert(String.prototype.repeat.length === 1);
+ expect("foo".repeat(0)).toBe("");
+ expect("foo".repeat(1)).toBe("foo");
+ expect("foo".repeat(2)).toBe("foofoo");
+ expect("foo".repeat(3)).toBe("foofoofoo");
+ expect("foo".repeat(3.1)).toBe("foofoofoo");
+ expect("foo".repeat(3.5)).toBe("foofoofoo");
+ expect("foo".repeat(3.9)).toBe("foofoofoo");
+ expect("foo".repeat(null)).toBe("");
+ expect("foo".repeat(undefined)).toBe("");
+ expect("foo".repeat([])).toBe("");
+ expect("foo".repeat("")).toBe("");
+});
- try {
+test("throws correct range errors", () => {
+ expect(() => {
"foo".repeat(-1);
- assertNotReached();
- } catch (e) {
- assert(e.name === "RangeError");
- assert(e.message === "repeat count must be a positive number");
- }
+ }).toThrowWithMessage(RangeError, "repeat count must be a positive number");
- try {
+ expect(() => {
"foo".repeat(Infinity);
- assertNotReached();
- } catch (e) {
- assert(e.name === "RangeError");
- assert(e.message === "repeat count must be a finite number");
- }
-
- assert("foo".repeat(0) === "");
- assert("foo".repeat(1) === "foo");
- assert("foo".repeat(2) === "foofoo");
- assert("foo".repeat(3) === "foofoofoo");
- assert("foo".repeat(3.1) === "foofoofoo");
- assert("foo".repeat(3.5) === "foofoofoo");
- assert("foo".repeat(3.9) === "foofoofoo");
- assert("foo".repeat(null) === "");
- assert("foo".repeat(undefined) === "");
- assert("foo".repeat([]) === "");
- assert("foo".repeat("") === "");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ }).toThrowWithMessage(RangeError, "repeat count must be a finite number");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js
index a6500ed9d8..33bb1e374f 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.slice.js
@@ -1,22 +1,18 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.slice).toHaveLength(2);
-try {
- assert(String.prototype.slice.length === 2);
- assert("hello friends".slice() === "hello friends");
- assert("hello friends".slice(1) === "ello friends");
- assert("hello friends".slice(0, 5) === "hello");
- assert("hello friends".slice(13, 6) === "");
- assert("hello friends".slice('', 5) === "hello");
- assert("hello friends".slice(3, 3) === "");
- assert("hello friends".slice(-1, 13) === "s");
- assert("hello friends".slice(0, 50) === "hello friends");
- assert("hello friends".slice(0, "5") === "hello");
- assert("hello friends".slice("6", "13") === "friends");
- assert("hello friends".slice(-7) === "friends");
- assert("hello friends".slice(1000) === "");
- assert("hello friends".slice(-1000) === "hello friends");
+ expect("hello friends".slice()).toBe("hello friends");
+ expect("hello friends".slice(1)).toBe("ello friends");
+ expect("hello friends".slice(0, 5)).toBe("hello");
+ expect("hello friends".slice(13, 6)).toBe("");
+ expect("hello friends".slice("", 5)).toBe("hello");
+ expect("hello friends".slice(3, 3)).toBe("");
+ expect("hello friends".slice(-1, 13)).toBe("s");
+ expect("hello friends".slice(0, 50)).toBe("hello friends");
+ expect("hello friends".slice(0, "5")).toBe("hello");
+ expect("hello friends".slice("6", "13")).toBe("friends");
+ expect("hello friends".slice(-7)).toBe("friends");
+ expect("hello friends".slice(1000)).toBe("");
+ expect("hello friends".slice(-1000)).toBe("hello friends");
+});
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js
index 2ed6d486f5..5114da78f9 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.startsWith.js
@@ -1,40 +1,36 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.startsWith).toHaveLength(1);
-try {
var s = "foobar";
- assert(s.startsWith("f") === true);
- assert(s.startsWith("fo") === true);
- assert(s.startsWith("foo") === true);
- assert(s.startsWith("foob") === true);
- assert(s.startsWith("fooba") === true);
- assert(s.startsWith("foobar") === true);
- assert(s.startsWith("foobar1") === false);
- assert(s.startsWith("f", 0) === true);
- assert(s.startsWith("fo", 0) === true);
- assert(s.startsWith("foo", 0) === true);
- assert(s.startsWith("foob", 0) === true);
- assert(s.startsWith("fooba", 0) === true);
- assert(s.startsWith("foobar", 0) === true);
- assert(s.startsWith("foobar1", 0) === false);
- assert(s.startsWith("foo", []) === true);
- assert(s.startsWith("foo", null) === true);
- assert(s.startsWith("foo", undefined) === true);
- assert(s.startsWith("foo", false) === true);
- assert(s.startsWith("foo", true) === false);
- assert(s.startsWith("foo", "foo") === true);
- assert(s.startsWith("foo", -1) === true);
- assert(s.startsWith("foo", 42) === false);
- assert(s.startsWith("bar", 3) === true);
- assert(s.startsWith("bar", "3") === true);
- assert(s.startsWith("bar1", 3) === false);
- assert(s.startsWith() === false);
- assert(s.startsWith("") === true);
- assert(s.startsWith("", 0) === true);
- assert(s.startsWith("", 1) === true);
- assert(s.startsWith("", -1) === true);
- assert(s.startsWith("", 42) === true);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(s.startsWith("f")).toBeTrue();
+ expect(s.startsWith("fo")).toBeTrue();
+ expect(s.startsWith("foo")).toBeTrue();
+ expect(s.startsWith("foob")).toBeTrue();
+ expect(s.startsWith("fooba")).toBeTrue();
+ expect(s.startsWith("foobar")).toBeTrue();
+ expect(s.startsWith("foobar1")).toBeFalse();
+ expect(s.startsWith("f", 0)).toBeTrue();
+ expect(s.startsWith("fo", 0)).toBeTrue();
+ expect(s.startsWith("foo", 0)).toBeTrue();
+ expect(s.startsWith("foob", 0)).toBeTrue();
+ expect(s.startsWith("fooba", 0)).toBeTrue();
+ expect(s.startsWith("foobar", 0)).toBeTrue();
+ expect(s.startsWith("foobar1", 0)).toBeFalse();
+ expect(s.startsWith("foo", [])).toBeTrue();
+ expect(s.startsWith("foo", null)).toBeTrue();
+ expect(s.startsWith("foo", undefined)).toBeTrue();
+ expect(s.startsWith("foo", false)).toBeTrue();
+ expect(s.startsWith("foo", true)).toBeFalse();
+ expect(s.startsWith("foo", "foo")).toBeTrue();
+ expect(s.startsWith("foo", -1)).toBeTrue();
+ expect(s.startsWith("foo", 42)).toBeFalse();
+ expect(s.startsWith("bar", 3)).toBeTrue();
+ expect(s.startsWith("bar", "3")).toBeTrue();
+ expect(s.startsWith("bar1", 3)).toBeFalse();
+ expect(s.startsWith()).toBeFalse();
+ expect(s.startsWith("")).toBeTrue();
+ expect(s.startsWith("", 0)).toBeTrue();
+ expect(s.startsWith("", 1)).toBeTrue();
+ expect(s.startsWith("", -1)).toBeTrue();
+ expect(s.startsWith("", 42)).toBeTrue();
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js
index 134906a3b0..294d756898 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.substring.js
@@ -1,19 +1,14 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.substring).toHaveLength(2);
-try {
- assert(String.prototype.substring.length === 2);
- assert("hello friends".substring() === "hello friends");
- assert("hello friends".substring(1) === "ello friends");
- assert("hello friends".substring(0, 5) === "hello");
- assert("hello friends".substring(13, 6) === "friends");
- assert("hello friends".substring('', 5) === "hello");
- assert("hello friends".substring(3, 3) === "");
- assert("hello friends".substring(-1, 13) === "hello friends");
- assert("hello friends".substring(0, 50) === "hello friends");
- assert("hello friends".substring(0, "5") === "hello");
- assert("hello friends".substring("6", "13") === "friends");
-
- console.log("PASS");
-} catch (err) {
- console.log("FAIL: " + err);
-}
+ expect("hello friends".substring()).toBe("hello friends");
+ expect("hello friends".substring(1)).toBe("ello friends");
+ expect("hello friends".substring(0, 5)).toBe("hello");
+ expect("hello friends".substring(13, 6)).toBe("friends");
+ expect("hello friends".substring('', 5)).toBe("hello");
+ expect("hello friends".substring(3, 3)).toBe("");
+ expect("hello friends".substring(-1, 13)).toBe("hello friends");
+ expect("hello friends".substring(0, 50)).toBe("hello friends");
+ expect("hello friends".substring(0, "5")).toBe("hello");
+ expect("hello friends".substring("6", "13")).toBe("friends");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js
index 571f26e729..8823cfda45 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.toLowerCase.js
@@ -1,15 +1,9 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.toLowerCase).toHaveLength(0);
-try {
- assert(String.prototype.toLowerCase.length === 0);
+ expect("foo".toLowerCase()).toBe("foo");
+ expect("Foo".toLowerCase()).toBe("foo");
+ expect("FOO".toLowerCase()).toBe("foo");
- assert("foo".toLowerCase() === "foo");
- assert("Foo".toLowerCase() === "foo");
- assert("FOO".toLowerCase() === "foo");
-
- assert(('b' + 'a' + + 'a' + 'a').toLowerCase() === "banana");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(('b' + 'a' + + 'a' + 'a').toLowerCase()).toBe("banana");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js
index 3be304ed1e..59a6885772 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js
@@ -1,11 +1,6 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.toString).toHaveLength(0)
-try {
- assert(String.prototype.toString.length === 0)
- assert("".toString() === "");
- assert("hello friends".toString() === "hello friends");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect("".toString()).toBe("");
+ expect("hello friends".toString()).toBe("hello friends");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js
index c1532dfa22..1c4877d071 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.toUpperCase.js
@@ -1,15 +1,9 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(String.prototype.toUpperCase).toHaveLength(0);
-try {
- assert(String.prototype.toUpperCase.length === 0);
+ expect("foo".toUpperCase()).toBe("FOO");
+ expect("Foo".toUpperCase()).toBe("FOO");
+ expect("FOO".toUpperCase()).toBe("FOO");
- assert("foo".toUpperCase() === "FOO");
- assert("Foo".toUpperCase() === "FOO");
- assert("FOO".toUpperCase() === "FOO");
-
- assert(('b' + 'a' + + 'n' + 'a').toUpperCase() === "BANANA");
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ expect(('b' + 'a' + + 'n' + 'a').toUpperCase()).toBe("BANANA");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js
index d8eb446767..d60522cad4 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js
@@ -1,56 +1,58 @@
-load("test-common.js");
-
-try {
- assert(String.prototype.trim.length === 0);
- assert(String.prototype.trimStart.length === 0);
- assert(String.prototype.trimEnd.length === 0);
- assert(" hello friends ".trim() === "hello friends");
- assert("hello friends ".trim() === "hello friends");
- assert(" hello friends".trim() === "hello friends");
- assert(" hello friends".trimStart() === "hello friends");
- assert("hello friends ".trimEnd() === "hello friends");
- assert(" hello friends".trimEnd() === " hello friends");
- assert("hello friends ".trimStart() === "hello friends ");
- assert(" hello friends ".trimEnd() === " hello friends");
- assert(" hello friends ".trimStart() === "hello friends ");
-
- assert("\thello friends".trimStart() === "hello friends");
- assert("hello friends\t".trimStart() === "hello friends\t");
- assert("\thello friends\t".trimStart() === "hello friends\t");
-
- assert("\rhello friends".trimStart() === "hello friends");
- assert("hello friends\r".trimStart() === "hello friends\r");
- assert("\rhello friends\r".trimStart() === "hello friends\r");
-
- assert("hello friends\t".trimEnd() === "hello friends");
- assert("\thello friends".trimEnd() === "\thello friends");
- assert("\thello friends\t".trimEnd() === "\thello friends");
-
- assert("hello friends\r".trimEnd() === "hello friends");
- assert("\rhello friends".trimEnd() === "\rhello friends");
- assert("\rhello friends\r".trimEnd() === "\rhello friends");
-
- assert("hello friends\n".trimEnd() === "hello friends");
- assert("\r\nhello friends".trimEnd() === "\r\nhello friends");
- assert("\rhello friends\r\n".trimEnd() === "\rhello friends");
-
- assert("\thello friends\t".trim() === "hello friends");
- assert("\thello friends".trim() === "hello friends");
- assert("hello friends\t".trim() === "hello friends");
-
- assert("\rhello friends\r".trim() === "hello friends");
- assert("\rhello friends".trim() === "hello friends");
- assert("hello friends\r".trim() === "hello friends");
-
- assert("\rhello friends\n".trim() === "hello friends");
- assert("\r\thello friends".trim() === "hello friends");
- assert("hello friends\r\n".trim() === "hello friends");
- assert(" \thello friends\r\n".trim() === "hello friends");
- assert("\n\t\thello friends\r\n".trim() === "hello friends");
- assert("\n\t\thello friends\t\t".trim() === "hello friends");
-
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+test("trim", () => {
+ expect(String.prototype.trim).toHaveLength(0);
+
+ expect(" hello friends ".trim()).toBe("hello friends");
+ expect("hello friends ".trim()).toBe("hello friends");
+ expect(" hello friends".trim()).toBe("hello friends");
+
+ expect("\thello friends\t".trim()).toBe("hello friends");
+ expect("\thello friends".trim()).toBe("hello friends");
+ expect("hello friends\t".trim()).toBe("hello friends");
+
+ expect("\rhello friends\r".trim()).toBe("hello friends");
+ expect("\rhello friends".trim()).toBe("hello friends");
+ expect("hello friends\r".trim()).toBe("hello friends");
+
+ expect("\rhello friends\n".trim()).toBe("hello friends");
+ expect("\r\thello friends".trim()).toBe("hello friends");
+ expect("hello friends\r\n".trim()).toBe("hello friends");
+ expect(" \thello friends\r\n".trim()).toBe("hello friends");
+ expect("\n\t\thello friends\r\n".trim()).toBe("hello friends");
+ expect("\n\t\thello friends\t\t".trim()).toBe("hello friends");
+});
+
+test("trimStart", () => {
+ expect(String.prototype.trimStart).toHaveLength(0);
+
+ expect(" hello friends".trimStart()).toBe("hello friends");
+ expect("hello friends ".trimStart()).toBe("hello friends ");
+ expect(" hello friends ".trimStart()).toBe("hello friends ");
+
+ expect("\thello friends".trimStart()).toBe("hello friends");
+ expect("hello friends\t".trimStart()).toBe("hello friends\t");
+ expect("\thello friends\t".trimStart()).toBe("hello friends\t");
+
+ expect("\rhello friends".trimStart()).toBe("hello friends");
+ expect("hello friends\r".trimStart()).toBe("hello friends\r");
+ expect("\rhello friends\r".trimStart()).toBe("hello friends\r");
+});
+
+test("trimEnd", () => {
+ expect(String.prototype.trimEnd).toHaveLength(0);
+
+ expect("hello friends ".trimEnd()).toBe("hello friends");
+ expect(" hello friends".trimEnd()).toBe(" hello friends");
+ expect(" hello friends ".trimEnd()).toBe(" hello friends");
+
+ expect("hello friends\t".trimEnd()).toBe("hello friends");
+ expect("\thello friends".trimEnd()).toBe("\thello friends");
+ expect("\thello friends\t".trimEnd()).toBe("\thello friends");
+
+ expect("hello friends\r".trimEnd()).toBe("hello friends");
+ expect("\rhello friends".trimEnd()).toBe("\rhello friends");
+ expect("\rhello friends\r".trimEnd()).toBe("\rhello friends");
+
+ expect("hello friends\n".trimEnd()).toBe("hello friends");
+ expect("\r\nhello friends".trimEnd()).toBe("\r\nhello friends");
+ expect("\rhello friends\r\n".trimEnd()).toBe("\rhello friends");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js
new file mode 100644
index 0000000000..9831064a0b
--- /dev/null
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.valueOf.js
@@ -0,0 +1,12 @@
+test("basic functionality", () => {
+ expect(String.prototype.valueOf).toHaveLength(0);
+
+ expect(String()).toBe("");
+ expect(new String().valueOf()).toBe("");
+ expect(String("foo")).toBe("foo");
+ expect(new String("foo").valueOf()).toBe("foo");
+ expect(String(123)).toBe("123");
+ expect(new String(123).valueOf()).toBe("123");
+ expect(String(123)).toBe("123");
+ expect(new String(123).valueOf()).toBe("123");
+});
diff --git a/Libraries/LibJS/Tests/builtins/String/String.raw.js b/Libraries/LibJS/Tests/builtins/String/String.raw.js
index 6a4e172b73..a866276034 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.raw.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.raw.js
@@ -1,35 +1,31 @@
-load("test-common.js")
+test("basic functionality", () => {
+ expect(String.raw).toHaveLength(1);
-try {
let str = String.raw`foo\nbar`;
- assert(str.length === 8 && str === "foo\\nbar");
+ expect(str).toHaveLength(8);
+ expect(str).toBe("foo\\nbar");
str = String.raw`foo ${1 + 9}\nbar${"hf!"}`;
- assert(str === "foo 10\\nbarhf!");
+ expect(str).toBe("foo 10\\nbarhf!");
str = String.raw`${10}${20}${30}`;
- assert(str === "102030");
+ expect(str).toBe("102030");
str = String.raw({ raw: ["foo ", "\\nbar"] }, 10, "hf!");
- assert(str === "foo 10\\nbar");
+ expect(str).toBe("foo 10\\nbar");
str = String.raw({ raw: ["foo ", "\\nbar"] });
- assert(str === "foo \\nbar");
+ expect(str).toBe("foo \\nbar");
str = String.raw({ raw: [] }, 10, "hf!");
- assert(str === "");
+ expect(str).toBe("");
str = String.raw({ raw: 1 });
- assert(str === "");
+ expect(str).toBe("");
+});
- assertThrowsError(() => {
+test("passing object with no 'raw' property", () => {
+ expect(() => {
String.raw({});
- }, {
- error: TypeError,
- message: "Cannot convert property 'raw' to object from undefined",
- });
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e);
-}
+ }).toThrowWithMessage(TypeError, "Cannot convert property 'raw' to object from undefined");
+});
diff --git a/Libraries/LibJS/Tests/builtins/functions/isFinite.js b/Libraries/LibJS/Tests/builtins/functions/isFinite.js
index 03d4f3d8b6..71f4f70655 100644
--- a/Libraries/LibJS/Tests/builtins/functions/isFinite.js
+++ b/Libraries/LibJS/Tests/builtins/functions/isFinite.js
@@ -1,29 +1,23 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(isFinite).toHaveLength(1);
-try {
- assert(isFinite.length === 1);
+ expect(isFinite(0)).toBeTrue();
+ expect(isFinite(1.23)).toBeTrue();
+ expect(isFinite(42)).toBeTrue();
+ expect(isFinite("")).toBeTrue();
+ expect(isFinite("0")).toBeTrue();
+ expect(isFinite("42")).toBeTrue();
+ expect(isFinite(true)).toBeTrue();
+ expect(isFinite(false)).toBeTrue();
+ expect(isFinite(null)).toBeTrue();
+ expect(isFinite([])).toBeTrue();
- assert(isFinite(0) === true);
- assert(isFinite(1.23) === true);
- assert(isFinite(42) === true);
- assert(isFinite("") === true);
- assert(isFinite("0") === true);
- assert(isFinite("42") === true);
- assert(isFinite(true) === true);
- assert(isFinite(false) === true);
- assert(isFinite(null) === true);
- assert(isFinite([]) === true);
-
- assert(isFinite() === false);
- assert(isFinite(NaN) === false);
- assert(isFinite(undefined) === false);
- assert(isFinite(Infinity) === false);
- assert(isFinite(-Infinity) === false);
- assert(isFinite("foo") === false);
- assert(isFinite({}) === false);
- assert(isFinite([1, 2, 3]) === false);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e.message);
-}
+ expect(isFinite()).toBeFalse();
+ expect(isFinite(NaN)).toBeFalse();
+ expect(isFinite(undefined)).toBeFalse();
+ expect(isFinite(Infinity)).toBeFalse();
+ expect(isFinite(-Infinity)).toBeFalse();
+ expect(isFinite("foo")).toBeFalse();
+ expect(isFinite({})).toBeFalse();
+ expect(isFinite([1, 2, 3])).toBeFalse();
+});
diff --git a/Libraries/LibJS/Tests/builtins/functions/isNaN.js b/Libraries/LibJS/Tests/builtins/functions/isNaN.js
index 7519b68fd2..188050ef6e 100644
--- a/Libraries/LibJS/Tests/builtins/functions/isNaN.js
+++ b/Libraries/LibJS/Tests/builtins/functions/isNaN.js
@@ -1,28 +1,22 @@
-load("test-common.js");
+test("basic functionality", () => {
+ expect(isNaN).toHaveLength(1);
-try {
- assert(isNaN.length === 1);
+ expect(isNaN(0)).toBeFalse();
+ expect(isNaN(42)).toBeFalse();
+ expect(isNaN("")).toBeFalse();
+ expect(isNaN("0")).toBeFalse();
+ expect(isNaN("42")).toBeFalse();
+ expect(isNaN(true)).toBeFalse();
+ expect(isNaN(false)).toBeFalse();
+ expect(isNaN(null)).toBeFalse();
+ expect(isNaN([])).toBeFalse();
+ expect(isNaN(Infinity)).toBeFalse();
+ expect(isNaN(-Infinity)).toBeFalse();
- assert(isNaN(0) === false);
- assert(isNaN(42) === false);
- assert(isNaN("") === false);
- assert(isNaN("0") === false);
- assert(isNaN("42") === false);
- assert(isNaN(true) === false);
- assert(isNaN(false) === false);
- assert(isNaN(null) === false);
- assert(isNaN([]) === false);
- assert(isNaN(Infinity) === false);
- assert(isNaN(-Infinity) === false);
-
- assert(isNaN() === true);
- assert(isNaN(NaN) === true);
- assert(isNaN(undefined) === true);
- assert(isNaN("foo") === true);
- assert(isNaN({}) === true);
- assert(isNaN([1, 2, 3]) === true);
-
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e.message);
-}
+ expect(isNaN()).toBeTrue();
+ expect(isNaN(NaN)).toBeTrue();
+ expect(isNaN(undefined)).toBeTrue();
+ expect(isNaN("foo")).toBeTrue();
+ expect(isNaN({})).toBeTrue();
+ expect(isNaN([1, 2, 3])).toBeTrue();
+});
diff --git a/Libraries/LibJS/Tests/builtins/functions/parseFloat.js b/Libraries/LibJS/Tests/builtins/functions/parseFloat.js
index 89045b2900..20ca28e445 100644
--- a/Libraries/LibJS/Tests/builtins/functions/parseFloat.js
+++ b/Libraries/LibJS/Tests/builtins/functions/parseFloat.js
@@ -1,7 +1,5 @@
-load("test-common.js");
-
-try {
- const NUMBER_TEST_CASES = [
+test("parsing numbers", () => {
+ [
[0, 0],
[1, 1],
[.23, 0.23],
@@ -9,17 +7,15 @@ try {
[0.0123E+2, 1.23],
[1.23e4, 12300],
[Infinity, Infinity]
- ];
-
- NUMBER_TEST_CASES.forEach(test => {
- const value = test[0];
- const result = test[1];
- assert(parseFloat(value) === result);
- assert(parseFloat(+value) === result);
- assert(parseFloat(-value) === -result);
+ ].forEach(test => {
+ expect(parseFloat(test[0])).toBe(test[1]);
+ expect(parseFloat(+test[0])).toBe(test[1]);
+ expect(parseFloat(-test[0])).toBe(-test[1]);
});
+});
- const STRING_TEST_CASES = [
+test("parsing strings", () => {
+ [
["0", 0],
["1", 1],
[".23", 0.23],
@@ -27,23 +23,21 @@ try {
["0.0123E+2", 1.23],
["1.23e4", 12300],
["Infinity", Infinity]
- ];
-
- STRING_TEST_CASES.forEach(test => {
- const value = test[0];
- const result = test[1];
- assert(parseFloat(value) === result);
- assert(parseFloat(`+${value}`) === result);
- assert(parseFloat(`-${value}`) === -result);
- assert(parseFloat(`${value}foo`) === result);
- assert(parseFloat(`+${value}foo`) === result);
- assert(parseFloat(`-${value}foo`) === -result);
- assert(parseFloat(` \n \t ${value} \v foo `) === result);
- assert(parseFloat(` \r -${value} \f \n\n foo `) === -result);
- assert(parseFloat({ toString: () => value }) === result);
+ ].forEach(test => {
+ expect(parseFloat(test[0])).toBe(test[1]);
+ expect(parseFloat(`+${test[0]}`)).toBe(test[1]);
+ expect(parseFloat(`-${test[0]}`)).toBe(-test[1]);
+ expect(parseFloat(`${test[0]}foo`)).toBe(test[1]);
+ expect(parseFloat(`+${test[0]}foo`)).toBe(test[1]);
+ expect(parseFloat(`-${test[0]}foo`)).toBe(-test[1]);
+ expect(parseFloat(` \n \t ${test[0]} \v foo `)).toBe(test[1]);
+ expect(parseFloat(` \r -${test[0]} \f \n\n foo `)).toBe(-test[1]);
+ expect(parseFloat({ toString: () => test[0] })).toBe(test[1]);
});
+});
- const NAN_TEST_CASES = [
+test("parsing NaN", () => {
+ [
"",
[],
[],
@@ -56,16 +50,10 @@ try {
"foo+123",
"fooInfinity",
"foo+Infinity"
- ];
-
- assert(isNaN(parseFloat()));
- assert(isNaN(parseFloat("", 123, Infinity)));
-
- NAN_TEST_CASES.forEach(value => {
- assert(isNaN(parseFloat(value)));
+ ].forEach(value => {
+ expect(parseFloat(value)).toBeNaN();
});
- console.log("PASS");
-} catch (e) {
- console.log("FAIL: " + e)
-}
+ expect(parseFloat()).toBeNaN();
+ expect(parseFloat("", 123, Infinity)).toBeNaN();
+});
diff --git a/Libraries/LibJS/Tests/test-common-tests.js b/Libraries/LibJS/Tests/test-common-tests.js
index 15be575b21..7077662ef1 100644
--- a/Libraries/LibJS/Tests/test-common-tests.js
+++ b/Libraries/LibJS/Tests/test-common-tests.js
@@ -27,6 +27,26 @@ test("toBe", () => {
expect(1n).not.toBe(1);
});
+test("toBeCloseTo", () => {
+ expect(1).toBeCloseTo(1);
+ expect(1).not.toBeCloseTo(1.1);
+ expect(1).not.toBeCloseTo(1.01);
+ expect(1).not.toBeCloseTo(1.001);
+ expect(1).not.toBeCloseTo(1.0001);
+ expect(1).not.toBeCloseTo(1.00001);
+ expect(1).toBeCloseTo(1.000001);
+
+ [
+ ["foo", 1],
+ [1, "foo"],
+ [1n, 1],
+ ].forEach(arr => {
+ expect(() => {
+ expect(arr[0]).toBeCloseTo(arr[1]);
+ }).toThrow(ExpectationError);
+ });
+});
+
test("toHaveLength", () => {
expect([]).toHaveLength(0);
expect([]).not.toHaveLength(1);
@@ -116,6 +136,94 @@ test("toBeFalse", () => {
expect(0).not.toBeFalse();
});
+test("toBeLessThan", () => {
+ expect(0).toBeLessThan(1);
+ expect(0).toBeLessThan(0.1);
+ expect(1).not.toBeLessThan(1);
+ expect(1).not.toBeLessThan(0);
+
+ expect(0n).toBeLessThan(1n);
+ expect(1n).not.toBeLessThan(1n);
+ expect(1n).not.toBeLessThan(0n);
+
+ [
+ ["foo", 0],
+ [0, "foo"],
+ [0, 0n],
+ [0n, 0],
+ ].forEach(arr => {
+ expect(() => {
+ expect(arr[0]).toBeLessThan(arr[1]);
+ }).toThrow(ExpectationError);
+ });
+});
+
+test("toBeLessThanOrEqual", () => {
+ expect(0).toBeLessThanOrEqual(1);
+ expect(0).toBeLessThanOrEqual(0.1);
+ expect(1).toBeLessThanOrEqual(1);
+ expect(1).not.toBeLessThanOrEqual(0);
+
+ expect(0n).toBeLessThanOrEqual(1n);
+ expect(1n).toBeLessThanOrEqual(1n);
+ expect(1n).not.toBeLessThanOrEqual(0n);
+
+ [
+ ["foo", 0],
+ [0, "foo"],
+ [0, 0n],
+ [0n, 0],
+ ].forEach(arr => {
+ expect(() => {
+ expect(arr[0]).toBeLessThanOrEqual(arr[1]);
+ }).toThrow(ExpectationError);
+ });
+});
+
+test("toBeGreaterThan", () => {
+ expect(1).toBeGreaterThan(0);
+ expect(0.1).toBeGreaterThan(0);
+ expect(1).not.toBeGreaterThan(1);
+ expect(0).not.toBeGreaterThan(1);
+
+ expect(1n).toBeGreaterThan(0n);
+ expect(1n).not.toBeGreaterThan(1n);
+ expect(0n).not.toBeGreaterThan(1n);
+
+ [
+ ["foo", 0],
+ [0, "foo"],
+ [0, 0n],
+ [0n, 0],
+ ].forEach(arr => {
+ expect(() => {
+ expect(arr[0]).toBeGreaterThan(arr[1]);
+ }).toThrow(ExpectationError);
+ });
+});
+
+test("toBeGreaterThanOrEqual", () => {
+ expect(1).toBeGreaterThanOrEqual(0);
+ expect(0.1).toBeGreaterThanOrEqual(0);
+ expect(1).toBeGreaterThanOrEqual(1);
+ expect(0).not.toBeGreaterThanOrEqual(1);
+
+ expect(1n).toBeGreaterThanOrEqual(0n);
+ expect(1n).toBeGreaterThanOrEqual(1n);
+ expect(0n).not.toBeGreaterThanOrEqual(1n);
+
+ [
+ ["foo", 0],
+ [0, "foo"],
+ [0, 0n],
+ [0n, 0],
+ ].forEach(arr => {
+ expect(() => {
+ expect(arr[0]).toBeGreaterThanOrEqual(arr[1]);
+ }).toThrow(ExpectationError);
+ });
+});
+
test("toContain", () => {
expect([1, 2, 3]).toContain(1);
expect([1, 2, 3]).toContain(2);
diff --git a/Libraries/LibJS/Tests/test-common.js b/Libraries/LibJS/Tests/test-common.js
index 26baf26a3f..c707a57a7b 100644
--- a/Libraries/LibJS/Tests/test-common.js
+++ b/Libraries/LibJS/Tests/test-common.js
@@ -71,6 +71,16 @@ class Expector {
});
}
+ // FIXME: Take a precision argument like jest's toBeCloseTo matcher
+ toBeCloseTo(value) {
+ this.__expect(typeof this.target === "number");
+ this.__expect(typeof value === "number");
+
+ this.__doMatcher(() => {
+ this.__expect(Math.abs(this.target - value) < 0.000001);
+ })
+ }
+
toHaveLength(length) {
this.__expect(typeof this.target.length === "number");
@@ -153,7 +163,45 @@ class Expector {
toBeFalse() {
this.__doMatcher(() => {
this.__expect(this.target === false);
- })
+ });
+ }
+
+ __validateNumericComparisonTypes(value) {
+ this.__expect(typeof this.target === "number" || typeof this.target === "bigint");
+ this.__expect(typeof value === "number" || typeof value === "bigint");
+ this.__expect(typeof this.target === typeof value);
+ }
+
+ toBeLessThan(value) {
+ this.__validateNumericComparisonTypes(value);
+
+ this.__doMatcher(() => {
+ this.__expect(this.target < value);
+ });
+ }
+
+ toBeLessThanOrEqual(value) {
+ this.__validateNumericComparisonTypes(value);
+
+ this.__doMatcher(() => {
+ this.__expect(this.target <= value);
+ });
+ }
+
+ toBeGreaterThan(value) {
+ this.__validateNumericComparisonTypes(value);
+
+ this.__doMatcher(() => {
+ this.__expect(this.target > value);
+ });
+ }
+
+ toBeGreaterThanOrEqual(value) {
+ this.__validateNumericComparisonTypes(value);
+
+ this.__doMatcher(() => {
+ this.__expect(this.target >= value);
+ });
}
toContain(item) {
diff --git a/Userland/test-js.cpp b/Userland/test-js.cpp
index 71e030f7f7..dfc1ae58d1 100644
--- a/Userland/test-js.cpp
+++ b/Userland/test-js.cpp
@@ -42,6 +42,86 @@
// FIXME: Will eventually not be necessary when all tests are converted
Vector<String> tests_to_run = {
+ "builtins/Boolean/Boolean.js",
+ "builtins/Boolean/Boolean.prototype.js",
+ "builtins/Boolean/Boolean.prototype.toString.js",
+ "builtins/Boolean/Boolean.prototype.valueOf.js",
+ "builtins/Date/Date.js",
+ "builtins/Date/Date.now.js",
+ "builtins/Date/Date.prototype.getDate.js",
+ "builtins/Date/Date.prototype.getDay.js",
+ "builtins/Date/Date.prototype.getFullYear.js",
+ "builtins/Date/Date.prototype.getHours.js",
+ "builtins/Date/Date.prototype.getMilliseconds.js",
+ "builtins/Date/Date.prototype.getMinutes.js",
+ "builtins/Date/Date.prototype.getMonth.js",
+ "builtins/Date/Date.prototype.getSeconds.js",
+ "builtins/Date/Date.prototype.getTime.js",
+ "builtins/Error/Error.js",
+ "builtins/Error/Error.prototype.name.js",
+ "builtins/Error/Error.prototype.toString.js",
+ "builtins/Function/Function.js",
+ "builtins/Function/Function.prototype.apply.js",
+ "builtins/Function/Function.prototype.bind.js",
+ "builtins/Function/Function.prototype.call.js",
+ "builtins/Function/Function.prototype.toString.js",
+ "builtins/functions/isFinite.js",
+ "builtins/functions/isNaN.js",
+ "builtins/functions/parseFloat.js",
+ "builtins/Infinity/Infinity.js",
+ "builtins/JSON/JSON.parse.js",
+ "builtins/JSON/JSON.parse-reviver.js",
+ "builtins/JSON/JSON.stringify.js",
+ "builtins/JSON/JSON.stringify-order.js",
+ "builtins/JSON/JSON.stringify-proxy.js",
+ "builtins/JSON/JSON.stringify-replacer.js",
+ "builtins/JSON/JSON.stringify-space.js",
+ "builtins/Math/Math-constants.js",
+ "builtins/Math/Math.abs.js",
+ "builtins/Math/Math.acosh.js",
+ "builtins/Math/Math.asinh.js",
+ "builtins/Math/Math.atanh.js",
+ "builtins/Math/Math.cbrt.js",
+ "builtins/Math/Math.ceil.js",
+ "builtins/Math/Math.clz32.js",
+ "builtins/Math/Math.cos.js",
+ "builtins/Math/Math.exp.js",
+ "builtins/Math/Math.expm1.js",
+ "builtins/Math/Math.floor.js",
+ "builtins/Math/Math.log1p.js",
+ "builtins/Math/Math.max.js",
+ "builtins/Math/Math.min.js",
+ "builtins/Math/Math.pow.js",
+ "builtins/Math/Math.sign.js",
+ "builtins/Math/Math.sqrt.js",
+ "builtins/Math/Math.tan.js",
+ "builtins/Math/Math.trunc.js",
+ "builtins/NaN/NaN.js",
+ "builtins/Number/Number.js",
+ "builtins/Number/Number-constants.js",
+ "builtins/Number/Number.isFinite.js",
+ "builtins/Number/Number.isInteger.js",
+ "builtins/Number/Number.isNaN.js",
+ "builtins/Number/Number.isSafeInteger.js",
+ "builtins/Number/Number.parseFloat.js",
+ "builtins/Number/Number.prototype.js",
+ "builtins/Object/Object.js",
+ "builtins/Object/Object.defineProperty.js",
+ "builtins/Object/Object.entries.js",
+ "builtins/Object/Object.getOwnPropertyDescriptor.js",
+ "builtins/Object/Object.getOwnPropertyNames.js",
+ "builtins/Object/Object.getPrototypeOf.js",
+ "builtins/Object/Object.is.js",
+ "builtins/Object/Object.isExtensible.js",
+ "builtins/Object/Object.keys.js",
+ "builtins/Object/Object.preventExtensions.js",
+ "builtins/Object/Object.prototype.js",
+ "builtins/Object/Object.prototype.constructor.js",
+ "builtins/Object/Object.prototype.hasOwnProperty.js",
+ "builtins/Object/Object.prototype.toLocaleString.js",
+ "builtins/Object/Object.prototype.toString.js",
+ "builtins/Object/Object.setPrototypeOf.js",
+ "builtins/Object/Object.values.js",
"builtins/Proxy/Proxy.js",
"builtins/Proxy/Proxy.handler-apply.js",
"builtins/Proxy/Proxy.handler-construct.js",
@@ -54,7 +134,7 @@ Vector<String> tests_to_run = {
"builtins/Proxy/Proxy.handler-isExtensible.js",
"builtins/Proxy/Proxy.handler-preventExtensions.js",
"builtins/Proxy/Proxy.handler-set.js",
- "builtins/Proxy/Proxy.handler-setPrototypeOf.js",
+ "builtins/Proxy/Proxy.handler-setPrototypeOf.js",\
"builtins/Reflect/Reflect.apply.js",
"builtins/Reflect/Reflect.construct.js",
"builtins/Reflect/Reflect.defineProperty.js",
@@ -67,7 +147,27 @@ Vector<String> tests_to_run = {
"builtins/Reflect/Reflect.ownKeys.js",
"builtins/Reflect/Reflect.preventExtensions.js",
"builtins/Reflect/Reflect.set.js",
- "builtins/Reflect/Reflect.setPrototypeOf.js",
+ "builtins/Reflect/Reflect.setPrototypeOf.js",\
+ "builtins/String/String.js",
+ "builtins/String/String.fromCharCode.js",
+ "builtins/String/String.prototype.js",
+ "builtins/String/String.prototype-generic-functions.js",
+ "builtins/String/String.prototype.charAt.js",
+ "builtins/String/String.prototype.includes.js",
+ "builtins/String/String.prototype.indexOf.js",
+ "builtins/String/String.prototype.lastIndexOf.js",
+ "builtins/String/String.prototype.padEnd.js",
+ "builtins/String/String.prototype.padStart.js",
+ "builtins/String/String.prototype.repeat.js",
+ "builtins/String/String.prototype.slice.js",
+ "builtins/String/String.prototype.startsWith.js",
+ "builtins/String/String.prototype.substring.js",
+ "builtins/String/String.prototype.toLowerCase.js",
+ "builtins/String/String.prototype.toString.js",
+ "builtins/String/String.prototype.toUpperCase.js",
+ "builtins/String/String.prototype.trim.js",
+ "builtins/String/String.prototype.valueOf.js",
+ "builtins/String/String.raw.js",\
"add-values-to-primitive.js",
"automatic-semicolon-insertion.js",
"comments-basic.js",
@@ -122,7 +222,10 @@ Optional<TestError> parse_and_run_file(JS::Interpreter& interpreter, const Strin
{
auto file = Core::File::construct(path);
auto result = file->open(Core::IODevice::ReadOnly);
- ASSERT(result);
+ if (!result) {
+ dbg() << "Failed to open file " << path;
+ exit(1);
+ }
auto contents = file->read_all();
String test_file_string(reinterpret_cast<const char*>(contents.data()), contents.size());
@@ -158,7 +261,7 @@ FileResults run_test(const String& path, const String& test_root)
// FIXME: Should be printed to stdout in a nice format
auto& arr = interpreter->get_variable("__UserOutput__", interpreter->global_object()).as_array();
for (auto& entry : arr.indexed_properties()) {
- dbg() << "OUTPUT: " << entry.value_and_attributes(&interpreter->global_object()).value.to_string_without_side_effects();
+ dbg() << path << ": " << entry.value_and_attributes(&interpreter->global_object()).value.to_string_without_side_effects();
}
// FIXME: This is _so_ scuffed