Object.hasOwn.js 1011 B

1234567891011121314151617181920212223242526272829303132333435
  1. describe("basic functionality", () => {
  2. test("length", () => {
  3. expect(Object.hasOwn).toHaveLength(2);
  4. });
  5. test("returns true for existent own property", () => {
  6. const o = { foo: "bar" };
  7. expect(Object.hasOwn(o, "foo")).toBeTrue();
  8. });
  9. test("returns false for non-existent own property", () => {
  10. const o = {};
  11. expect(Object.hasOwn(o, "foo")).toBeFalse();
  12. });
  13. test("returns false for existent prototype chain property", () => {
  14. const o = {};
  15. Object.prototype.foo = "bar";
  16. expect(Object.hasOwn(o, "foo")).toBeFalse();
  17. });
  18. });
  19. describe("errors", () => {
  20. test("null argument", () => {
  21. expect(() => {
  22. Object.hasOwn(null);
  23. }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
  24. });
  25. test("undefined argument", () => {
  26. expect(() => {
  27. Object.hasOwn(undefined);
  28. }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
  29. });
  30. });