mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 19:47:17 +02:00
LibJS: Move tests to /Tests/LibJS
This commit is contained in:
committed by
Tim Flynn
parent
c059c6a2f5
commit
e3faa9b5ad
Notes:
github-actions[bot]
2026-02-06 11:17:48 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/e3faa9b5add Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7572 Reviewed-by: https://github.com/trflynn89 ✅
51
Tests/LibJS/Runtime/builtins/Object/Object.values.js
Normal file
51
Tests/LibJS/Runtime/builtins/Object/Object.values.js
Normal file
@@ -0,0 +1,51 @@
|
||||
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);
|
||||
});
|
||||
|
||||
test("object argument", () => {
|
||||
let values = Object.values({ foo: 1, bar: 2, baz: 3 });
|
||||
expect(values).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
test("object argument with symbol keys", () => {
|
||||
let values = Object.values({ foo: 1, [Symbol("bar")]: 2, baz: 3 });
|
||||
expect(values).toEqual([1, 3]);
|
||||
});
|
||||
|
||||
test("array argument", () => {
|
||||
let values = Object.values(["a", "b", "c"]);
|
||||
expect(values).toEqual(["a", "b", "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]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("null argument", () => {
|
||||
expect(() => {
|
||||
Object.values(null);
|
||||
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
|
||||
});
|
||||
|
||||
test("undefined argument", () => {
|
||||
expect(() => {
|
||||
Object.values(undefined);
|
||||
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user