FinalizationRegistry.js 1.0 KB

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