WeakRef.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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, "cannot be held weakly");
  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. test("constructor with single symbol argument", () => {
  28. var a = new WeakRef(Symbol());
  29. expect(a instanceof WeakRef).toBeTrue();
  30. });
  31. });