UNPKG

@scandit/web-datacapture-core

Version:

Scandit Data Capture SDK for the Web

1 lines 2.48 kB
import {a}from'../chunks/chunk-SEAVQZN6.js';var o=globalThis;describe("FinalizationRegistry Polyfill",()=>{let l;beforeAll(()=>{l=o.FinalizationRegistry,o.FinalizationRegistry=void 0;}),beforeEach(()=>{o.FinalizationRegistry=void 0;}),afterEach(()=>{l&&(o.FinalizationRegistry=l);}),it("should create a polyfill when FinalizationRegistry is not available",()=>{expect(typeof o.FinalizationRegistry).toBe("undefined"),a(globalThis),expect(typeof o.FinalizationRegistry).toBe("function");}),it("should allow creating FinalizationRegistry instances without errors",()=>{a(globalThis);let i=jest.fn(),t=o.FinalizationRegistry;if(expect(t).toBeDefined(),t){let e=new t(i);expect(typeof e.register).toBe("function"),expect(typeof e.unregister).toBe("function");}}),it("should allow registration and unregistration without errors",()=>{a(globalThis);let i=jest.fn(),t=o.FinalizationRegistry;if(expect(t).toBeDefined(),t){let e=new t(i),n={},a="test-value";expect(()=>{e.register(n,a);}).not.toThrow(),expect(()=>{let r=e.unregister(n);expect(r).toBe(false);}).not.toThrow();}}),it("should not override FinalizationRegistry if it already exists",()=>{o.FinalizationRegistry=l;let i=o.FinalizationRegistry;a(globalThis),expect(o.FinalizationRegistry).toBe(i);}),it("should provide tracking functionality using WeakMap",()=>{a(globalThis);let i=jest.fn(),t=o.FinalizationRegistry;if(expect(t).toBeDefined(),t){let e=new t(i),n={},a="test-value";expect(()=>{e.register(n,a);}).not.toThrow();let r=e.unregister(n);expect(r).toBe(false),expect(i).not.toHaveBeenCalled();}}),it("should work with multiple registrations",()=>{a(globalThis);let i=jest.fn(),t=o.FinalizationRegistry;if(expect(t).toBeDefined(),t){let e=new t(i),n={},a={},r="value1",c="value2";expect(()=>{e.register(n,r),e.register(a,c);}).not.toThrow(),expect(e.unregister(n)).toBe(false),expect(e.unregister(a)).toBe(false);}}),it("should return false for unregistered objects",()=>{a(globalThis);let i=jest.fn(),t=o.FinalizationRegistry;if(expect(t).toBeDefined(),t){let e=new t(i),n={},a={};e.register(n,"test-value"),expect(e.unregister(n)).toBe(false),expect(e.unregister(a)).toBe(false);}}),it("should work with different target objects",()=>{let i={};i.FinalizationRegistry=void 0,a(i),expect(typeof i.FinalizationRegistry).toBe("function");}),it("should be compatible with WeakMap browser support",()=>{expect(typeof WeakMap).toBe("function");let i=new WeakMap,t={},e="test-value";i.set(t,e),expect(i.get(t)).toBe(e);});});