From f3637f935b4938fa0b4a59c8cf8ef4c81322a4cf Mon Sep 17 00:00:00 2001 From: Andrew Gerard <63810935+agerard-godaddy@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:07:22 -0700 Subject: [PATCH] test: using gasket.symbol as weakmap key (#964) --- packages/gasket-core/test/gasket.test.js | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/gasket-core/test/gasket.test.js b/packages/gasket-core/test/gasket.test.js index c65db57e2..e856f3dcf 100644 --- a/packages/gasket-core/test/gasket.test.js +++ b/packages/gasket-core/test/gasket.test.js @@ -82,6 +82,34 @@ describe('makeGasket', () => { expect(gasket.symbol).toBe(gasket.traceBranch().traceBranch().symbol); }); + it('symbol can be used as a WeakMap key from root', () => { + const data = { example: true }; + const map = new WeakMap(); + + const gasket = makeGasket({ plugins: [mockPlugin] }); + const t1 = gasket.traceBranch(); + const t2 = t1.traceBranch(); + map.set(gasket.symbol, data); + + expect(map.has(gasket.symbol)).toBe(true); + expect(map.has(t1.symbol)).toBe(true); + expect(map.has(t2.symbol)).toBe(true); + }); + + it('symbol can be used as a WeakMap key from deep trace', () => { + const data = { example: true }; + const map = new WeakMap(); + + const gasket = makeGasket({ plugins: [mockPlugin] }); + const t1 = gasket.traceBranch(); + const t2 = t1.traceBranch(); + map.set(t2.symbol, data); + + expect(map.has(t2.symbol)).toBe(true); + expect(map.has(t1.symbol)).toBe(true); + expect(map.has(gasket.symbol)).toBe(true); + }); + it('defaults env to local', () => { const gasket = makeGasket({ plugins: [mockPlugin] }); expect(gasket.config.env).toEqual('local');