1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:37:36 +00:00

Libraries: Move to Userland/Libraries/

This commit is contained in:
Andreas Kling 2021-01-12 12:17:30 +01:00
parent dc28c07fa5
commit 13d7c09125
1857 changed files with 266 additions and 274 deletions

View file

@ -0,0 +1,242 @@
describe("normal functionality", () => {
let s = Symbol("foo");
test("non-configurable string 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);
});
test("non-configurable symbol property", () => {
let o = {};
Object.defineProperty(o, s, { value: 1, writable: false, enumerable: false });
expect(o[s]).toBe(1);
o[s] = 2;
expect(o[s]).toBe(1);
expect(o).not.toHaveConfigurableProperty(s);
expect(o).not.toHaveEnumerableProperty(s);
expect(o).not.toHaveWritableProperty(s);
expect(o).toHaveValueProperty(s, 1);
});
test("array index getter", () => {
let o = {};
Object.defineProperty(o, 2, {
get() {
return 10;
},
});
expect(o[2]).toBe(10);
});
test("symbol property getter", () => {
let o = {};
Object.defineProperty(o, s, {
get() {
return 10;
},
});
expect(o[s]).toBe(10);
});
test("configurable string 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");
});
test("configurable symbol property", () => {
let o = {};
Object.defineProperty(o, s, { value: "hi", writable: true, enumerable: true });
expect(o[s]).toBe("hi");
o[s] = "ho";
expect(o[s]).toBe("ho");
expect(o).not.toHaveConfigurableProperty(s);
expect(o).toHaveEnumerableProperty(s);
expect(o).toHaveWritableProperty(s);
expect(o).toHaveValueProperty(s, "ho");
});
test("reconfigure configurable string property", () => {
let o = {};
Object.defineProperty(o, "foo", { value: 9, configurable: true, writable: false });
Object.defineProperty(o, "foo", { configurable: true, writable: true });
expect(o).toHaveConfigurableProperty("foo");
expect(o).toHaveWritableProperty("foo");
expect(o).not.toHaveEnumerableProperty("foo");
expect(o).toHaveValueProperty("foo", 9);
});
test("reconfigure configurable symbol property", () => {
let o = {};
Object.defineProperty(o, s, { value: 9, configurable: true, writable: false });
Object.defineProperty(o, s, { configurable: true, writable: true });
expect(o).toHaveConfigurableProperty(s);
expect(o).toHaveWritableProperty(s);
expect(o).not.toHaveEnumerableProperty(s);
expect(o).toHaveValueProperty(s, 9);
});
test("define string accessor", () => {
let o = {};
Object.defineProperty(o, "foo", {
configurable: true,
get() {
return o.secret_foo + 1;
},
set(value) {
this.secret_foo = value + 1;
},
});
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);
});
test("define symbol accessor", () => {
let o = {};
Object.defineProperty(o, s, {
configurable: true,
get() {
return o.secret_foo + 1;
},
set(value) {
this.secret_foo = value + 1;
},
});
o[s] = 10;
expect(o[s]).toBe(12);
o[s] = 20;
expect(o[s]).toBe(22);
Object.defineProperty(o, s, { configurable: true, value: 4 });
expect(o[s]).toBe(4);
expect((o[s] = 5)).toBe(5);
expect((o[s] = 4)).toBe(4);
});
test("issue #3735, reconfiguring property in unique shape", () => {
const o = {};
// In LibJS an object with more than 100 properties gets a unique shape
for (let i = 0; i < 101; ++i) {
o[`property${i}`] = i;
}
Object.defineProperty(o, "x", { configurable: true });
Object.defineProperty(o, "x", { configurable: false });
});
});
describe("errors", () => {
test("redefine non-configurable property", () => {
let o = {};
Object.defineProperty(o, "foo", { value: 1, writable: true, enumerable: true });
expect(() => {
Object.defineProperty(o, "foo", { value: 2, writable: false, enumerable: true });
}).toThrowWithMessage(
TypeError,
"Cannot change attributes of non-configurable property 'foo'"
);
});
test("redefine non-configurable symbol property", () => {
let o = {};
let s = Symbol("foo");
Object.defineProperty(o, s, { value: 1, writable: true, enumerable: true });
expect(() => {
Object.defineProperty(o, s, { value: 2, writable: false, enumerable: true });
}).toThrowWithMessage(
TypeError,
"Cannot change attributes of non-configurable property 'Symbol(foo)'"
);
});
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"
);
});
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"
);
});
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'"
);
});
});

View file

@ -0,0 +1,64 @@
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);
});
test("entries with object", () => {
let entries = Object.entries({ foo: 1, bar: 2, baz: 3 });
expect(entries).toEqual([
["foo", 1],
["bar", 2],
["baz", 3],
]);
});
test("entries with objects with symbol keys", () => {
let entries = Object.entries({ foo: 1, [Symbol("bar")]: 2, baz: 3 });
expect(entries).toEqual([
["foo", 1],
["baz", 3],
]);
});
test("entries with array", () => {
entries = Object.entries(["a", "b", "c"]);
expect(entries).toEqual([
["0", "a"],
["1", "b"],
["2", "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]]);
});
});
describe("errors", () => {
test("null argument", () => {
expect(() => {
Object.entries(null);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
test("undefined argument", () => {
expect(() => {
Object.entries(undefined);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
});

View file

@ -0,0 +1,61 @@
test("plain property", () => {
let o = { foo: "bar" };
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");
});
test("symbol property", () => {
let s = Symbol("foo");
let o = { [s]: "bar" };
expect(o).toHaveConfigurableProperty(s);
expect(o).toHaveEnumerableProperty(s);
expect(o).toHaveWritableProperty(s);
expect(o).toHaveValueProperty(s, "bar");
expect(o).not.toHaveGetterProperty(s);
expect(o).not.toHaveSetterProperty(s);
});
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,
});
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");
});

View file

@ -0,0 +1,14 @@
test("use with array", () => {
let names = Object.getOwnPropertyNames([1, 2, 3]);
expect(names).toEqual(["0", "1", "2", "length"]);
});
test("use with object", () => {
let names = Object.getOwnPropertyNames({ foo: 1, bar: 2, baz: 3 });
expect(names).toEqual(["foo", "bar", "baz"]);
});
test("use with object with symbol keys", () => {
let names = Object.getOwnPropertyNames({ foo: 1, [Symbol("bar")]: 2, baz: 3 });
expect(names).toEqual(["foo", "baz"]);
});

View file

@ -0,0 +1,10 @@
test("basic functionality", () => {
let o1 = new Object();
let o2 = {};
expect(Object.getPrototypeOf(o1)).toBe(Object.getPrototypeOf(o2));
expect(Object.getPrototypeOf(Object.getPrototypeOf(o1))).toBeNull();
Object.setPrototypeOf(o1, o2);
expect(Object.getPrototypeOf(o1)).toBe(o2);
});

View file

@ -0,0 +1,54 @@
test("length", () => {
expect(Object.is).toHaveLength(2);
});
test("arguments that evaluate to true", () => {
let a = [1, 2, 3];
let 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();
});
test("arguments that evaluate to false", () => {
let a = [1, 2, 3];
let o = { foo: "bar" };
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();
});

View file

@ -0,0 +1,18 @@
test("basic functionality", () => {
expect(Object.isExtensible).toHaveLength(1);
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();
expect(Object.isExtensible(s)).toBeFalse();
let o = { foo: "foo" };
expect(Object.isExtensible(o)).toBeTrue();
Object.preventExtensions(o);
expect(Object.isExtensible(o)).toBeFalse();
});

View file

@ -0,0 +1,13 @@
test("basic functionality", () => {
expect(Object).toHaveLength(1);
expect(Object.name).toBe("Object");
expect(Object.prototype).not.toHaveProperty("length");
expect(typeof Object()).toBe("object");
expect(typeof new Object()).toBe("object");
expect(typeof Object(42)).toBe("object");
expect(Object(42).valueOf()).toBe(42);
expect(typeof Object("foo")).toBe("object");
expect(Object("foo").valueOf()).toBe("foo");
});

View file

@ -0,0 +1,51 @@
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);
});
test("object argument", () => {
let keys = Object.keys({ foo: 1, bar: 2, baz: 3 });
expect(keys).toEqual(["foo", "bar", "baz"]);
});
test("object argument with symbol keys", () => {
let keys = Object.keys({ foo: 1, [Symbol("bar")]: 2, baz: 3 });
expect(keys).toEqual(["foo", "baz"]);
});
test("array argument", () => {
let keys = Object.keys(["a", "b", "c"]);
expect(keys).toEqual(["0", "1", "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"]);
});
});
describe("errors", () => {
test("null argument value", () => {
expect(() => {
Object.keys(null);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
test("undefined argument value", () => {
expect(() => {
Object.keys(undefined);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
});
});

View file

@ -0,0 +1,67 @@
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);
});
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");
o.baz = "baz";
expect(o.baz).toBeUndefined();
});
test("modifying existing properties", () => {
const o = { foo: "bar" };
Object.preventExtensions(o);
o.foo = "baz";
expect(o.foo).toBe("baz");
});
test("deleting existing properties", () => {
const o = { foo: "bar" };
Object.preventExtensions(o);
delete o.foo;
expect(o).not.toHaveProperty("foo");
});
});
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");
expect(o.baz).toBeUndefined();
});
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();
});
});

View file

@ -0,0 +1,18 @@
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);
});
let o = {};
expect(o.constructor).toBe(Object);
a = [];
expect(a.constructor).toBe(Array);
expect(Object.prototype).toHaveConfigurableProperty("constructor");
expect(Object.prototype).not.toHaveEnumerableProperty("constructor");
expect(Object.prototype).toHaveWritableProperty("constructor");
expect(Object.prototype).toHaveValueProperty("constructor", Object);
});

View file

@ -0,0 +1,13 @@
test("basic functionality", () => {
var o = {};
o.foo = 1;
expect(o.hasOwnProperty("foo")).toBeTrue();
expect(o.hasOwnProperty("bar")).toBeFalse();
expect(o.hasOwnProperty()).toBeFalse();
expect(o.hasOwnProperty(undefined)).toBeFalse();
o.undefined = 2;
expect(o.hasOwnProperty()).toBeTrue();
expect(o.hasOwnProperty(undefined)).toBeTrue();
});

View file

@ -0,0 +1,18 @@
test("basic functionality", () => {
function A() {}
function B() {}
A.prototype = new B();
const C = new A();
expect(A.prototype.isPrototypeOf(C)).toBeTrue();
expect(B.prototype.isPrototypeOf(C)).toBeTrue();
expect(A.isPrototypeOf(C)).toBeFalse();
expect(B.isPrototypeOf(C)).toBeFalse();
const D = new Object();
expect(Object.prototype.isPrototypeOf(D)).toBeTrue();
expect(Function.prototype.isPrototypeOf(D.toString)).toBeTrue();
expect(Array.prototype.isPrototypeOf([])).toBeTrue();
});

View file

@ -0,0 +1,5 @@
test("basic functionality", () => {
var o = new Object();
Object.prototype.foo = 123;
expect(o.foo).toBe(123);
});

View file

@ -0,0 +1,15 @@
test("basic functionality", () => {
var o = {};
o.foo = 1;
expect(o.propertyIsEnumerable("foo")).toBeTrue();
expect(o.propertyIsEnumerable("bar")).toBeFalse();
expect(o.propertyIsEnumerable()).toBeFalse();
expect(o.propertyIsEnumerable(undefined)).toBeFalse();
o.undefined = 2;
expect(o.propertyIsEnumerable()).toBeTrue();
expect(o.propertyIsEnumerable(undefined)).toBeTrue();
expect(globalThis.propertyIsEnumerable("globalThis")).toBeFalse();
});

View file

@ -0,0 +1,35 @@
describe("correct behavior", () => {
test("length", () => {
expect(Object.prototype.toLocaleString).toHaveLength(0);
});
test("basic functionality", () => {
let o;
o = {};
expect(o.toString()).toBe(o.toLocaleString());
o = { toString: () => 42 };
expect(o.toString()).toBe(42);
});
});
describe("errors", () => {
test("toString that throws error", () => {
let o = {
toString: () => {
throw new Error();
},
};
expect(() => {
o.toLocaleString();
}).toThrow(Error);
});
test("toString that is not a function", () => {
let o = { toString: "foo" };
expect(() => {
o.toLocaleString();
}).toThrowWithMessage(TypeError, "foo is not a function");
});
});

View file

@ -0,0 +1,20 @@
test("length", () => {
expect(Object.prototype.toString).toHaveLength(0);
});
test("result for various object types", () => {
const oToString = o => Object.prototype.toString.call(o);
expect(oToString(undefined)).toBe("[object Undefined]");
expect(oToString(null)).toBe("[object Null]");
expect(oToString([])).toBe("[object Array]");
expect(oToString(function () {})).toBe("[object Function]");
expect(oToString(new Error())).toBe("[object Error]");
expect(oToString(new Boolean())).toBe("[object Boolean]");
expect(oToString(new Number())).toBe("[object Number]");
expect(oToString(new Date())).toBe("[object Date]");
expect(oToString(new RegExp())).toBe("[object RegExp]");
expect(oToString({})).toBe("[object Object]");
expect(globalThis.toString()).toBe("[object Object]");
});

View file

@ -0,0 +1,43 @@
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);
});
});
describe("errors", () => {
test("requires two arguments", () => {
expect(() => {
Object.setPrototypeOf();
}).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments");
expect(() => {
Object.setPrototypeOf({});
}).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments");
});
test("prototype must be an object", () => {
expect(() => {
Object.setPrototypeOf({}, "foo");
}).toThrowWithMessage(TypeError, "Prototype must be an object or null");
});
test("non-extensible target", () => {
let o = {};
let p = {};
Object.setPrototypeOf(o, p);
Object.preventExtensions(o);
expect(() => {
Object.setPrototypeOf(o, {});
}).toThrowWithMessage(TypeError, "Object's [[SetPrototypeOf]] method returned false");
expect(Object.setPrototypeOf(o, p)).toBe(o);
});
});

View 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");
});
});