WeakRef.js 879 B

123456789101112131415161718192021222324252627282930
  1. test("constructor properties", () => {
  2. expect(WeakRef).toHaveLength(1);
  3. expect(WeakRef.name).toBe("WeakRef");
  4. });
  5. describe("errors", () => {
  6. test("invalid array iterators", () => {
  7. [-100, Infinity, NaN, 152n, undefined].forEach(value => {
  8. expect(() => {
  9. new WeakRef(value);
  10. }).toThrowWithMessage(TypeError, "is not an object");
  11. });
  12. });
  13. test("called without new", () => {
  14. expect(() => {
  15. WeakRef();
  16. }).toThrowWithMessage(TypeError, "WeakRef constructor must be called with 'new'");
  17. });
  18. });
  19. describe("normal behavior", () => {
  20. test("typeof", () => {
  21. expect(typeof new WeakRef({})).toBe("object");
  22. });
  23. test("constructor with single object argument", () => {
  24. var a = new WeakRef({});
  25. expect(a instanceof WeakRef).toBeTrue();
  26. });
  27. });