mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 08:25:07 +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,45 +1,25 @@
|
|||
load("test-common.js");
|
||||
|
||||
function testArray(arr) {
|
||||
return arr.length === 4 && arr[0] === 0 && arr[1] === 1 && arr[2] === 2 && arr[3] === 3;
|
||||
}
|
||||
|
||||
try {
|
||||
let arr = [0, ...[1, 2], 3];
|
||||
assert(testArray(arr));
|
||||
|
||||
let a = [1, 2];
|
||||
arr = [0, ...a, 3];
|
||||
assert(testArray(arr));
|
||||
|
||||
let obj = { a: [1, 2] };
|
||||
arr = [0, ...obj.a, 3];
|
||||
assert(testArray(arr));
|
||||
|
||||
arr = [...[], ...[...[0, 1, 2]], 3];
|
||||
assert(testArray(arr));
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
describe("errors", () => {
|
||||
test("cannot spread number in array", () => {
|
||||
expect(() => {
|
||||
[...1];
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "1 is not iterable",
|
||||
}
|
||||
);
|
||||
}).toThrowWithMessage(TypeError, "1 is not iterable");
|
||||
});
|
||||
|
||||
assertThrowsError(
|
||||
() => {
|
||||
test("cannot spread object in array", () => {
|
||||
expect(() => {
|
||||
[...{}];
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "[object Object] is not iterable",
|
||||
}
|
||||
);
|
||||
}).toThrowWithMessage(TypeError, "[object Object] is not iterable");
|
||||
});
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
test("basic functionality", () => {
|
||||
expect([1, ...[2, 3], 4]).toEqual([1, 2, 3, 4]);
|
||||
|
||||
let a = [2, 3];
|
||||
expect([1, ...a, 4]).toEqual([1, 2, 3, 4]);
|
||||
|
||||
let obj = { a: [2, 3] };
|
||||
expect([1, ...obj.a, 4]).toEqual([1, 2, 3, 4]);
|
||||
|
||||
expect([...[], ...[...[1, 2, 3]], 4]).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue