Object.getOwnPropertyNames.js 645 B

12345678910111213141516171819
  1. test("use with array", () => {
  2. let names = Object.getOwnPropertyNames([1, 2, 3]);
  3. expect(names).toEqual(["0", "1", "2", "length"]);
  4. });
  5. test("use with object", () => {
  6. let names = Object.getOwnPropertyNames({ foo: 1, bar: 2, baz: 3 });
  7. expect(names).toEqual(["foo", "bar", "baz"]);
  8. });
  9. test("use with object with symbol keys", () => {
  10. let names = Object.getOwnPropertyNames({ foo: 1, [Symbol("bar")]: 2, baz: 3 });
  11. expect(names).toEqual(["foo", "baz"]);
  12. });
  13. test("use with String object", () => {
  14. let names = Object.getOwnPropertyNames(new String("foo"));
  15. expect(names).toEqual(["0", "1", "2", "length"]);
  16. });