mirror of
https://github.com/RGBCube/serenity
synced 2025-07-03 05:22:08 +00:00
LibJS: Convert Array tests to new testing framework
This commit is contained in:
parent
8ebdf685a6
commit
461d90d042
33 changed files with 1315 additions and 1382 deletions
|
@ -1,55 +1,53 @@
|
|||
load("test-common.js");
|
||||
test("constructor properties", () => {
|
||||
expect(Array).toHaveLength(1);
|
||||
expect(Array.name).toBe("Array");
|
||||
expect(Array.prototype.length).toBe(0);
|
||||
});
|
||||
|
||||
try {
|
||||
assert(Array.length === 1);
|
||||
assert(Array.name === "Array");
|
||||
assert(Array.prototype.length === 0);
|
||||
|
||||
assert(typeof Array() === "object");
|
||||
assert(typeof new Array() === "object");
|
||||
|
||||
var a;
|
||||
|
||||
a = new Array(5);
|
||||
assert(a.length === 5);
|
||||
|
||||
a = new Array("5");
|
||||
assert(a.length === 1);
|
||||
assert(a[0] === "5");
|
||||
|
||||
a = new Array(1, 2, 3);
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 1);
|
||||
assert(a[1] === 2);
|
||||
assert(a[2] === 3);
|
||||
|
||||
a = new Array([1, 2, 3]);
|
||||
assert(a.length === 1);
|
||||
assert(a[0][0] === 1);
|
||||
assert(a[0][1] === 2);
|
||||
assert(a[0][2] === 3);
|
||||
|
||||
a = new Array(1, 2, 3);
|
||||
Object.defineProperty(a, 3, {
|
||||
get() {
|
||||
return 10;
|
||||
},
|
||||
});
|
||||
assert(a.toString() === "1,2,3,10");
|
||||
|
||||
[-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
describe("errors", () => {
|
||||
test("invalid array length", () => {
|
||||
[-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
expect(() => {
|
||||
new Array(value);
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Invalid array length",
|
||||
}
|
||||
);
|
||||
}).toThrowWithMessage(TypeError, "Invalid array length");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("typeof", () => {
|
||||
expect(typeof Array()).toBe("object");
|
||||
expect(typeof new Array()).toBe("object");
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
test("constructor with single numeric argument", () => {
|
||||
var a = new Array(5);
|
||||
expect(a instanceof Array).toBeTrue();
|
||||
expect(a).toHaveLength(5);
|
||||
});
|
||||
|
||||
test("constructor with single non-numeric argument", () => {
|
||||
var a = new Array("5");
|
||||
expect(a instanceof Array).toBeTrue();
|
||||
expect(a).toHaveLength(1);
|
||||
expect(a[0]).toBe("5");
|
||||
});
|
||||
|
||||
test("constructor with multiple numeric arguments", () => {
|
||||
var a = new Array(1, 2, 3);
|
||||
expect(a instanceof Array).toBeTrue();
|
||||
expect(a).toHaveLength(3);
|
||||
expect(a[0]).toBe(1);
|
||||
expect(a[1]).toBe(2);
|
||||
expect(a[2]).toBe(3);
|
||||
});
|
||||
|
||||
test("constructor with single array argument", () => {
|
||||
var a = new Array([1, 2, 3]);
|
||||
expect(a instanceof Array).toBeTrue();
|
||||
expect(a).toHaveLength(1);
|
||||
expect(a[0][0]).toBe(1);
|
||||
expect(a[0][1]).toBe(2);
|
||||
expect(a[0][2]).toBe(3);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue