import { resetSharedImpl } from '../__mocks__/reset-shared-impl'; import { getOrCreateSharedImpl, getSharedImpl, STATE_KEY } from '../get-shared'; describe(`[datadog-rum] ${getOrCreateSharedImpl.name}`, () => { beforeEach(() => { resetSharedImpl(); }); const subject = () => getOrCreateSharedImpl(); test('stores the instance under the well-known Symbol on globalThis', () => { const impl = subject(); expect((globalThis as any)[STATE_KEY]).toBe(impl); }); test('resolves the well-known Symbol from the package key', () => { expect(Symbol.for('@servicetitan/datadog-rum')).toBe(STATE_KEY); }); describe('when an instance already exists', () => { let first: ReturnType; beforeEach(() => { first = subject(); }); test('returns the same instance', () => { expect(subject()).toBe(first); }); }); }); describe(`[datadog-rum] ${getSharedImpl.name}`, () => { beforeEach(() => { resetSharedImpl(); }); const subject = () => getSharedImpl(); test('returns undefined', () => { expect(subject()).toBeUndefined(); }); describe('when an instance exists', () => { let impl: ReturnType; beforeEach(() => { impl = getOrCreateSharedImpl(); }); test('returns existing instance', () => { expect(subject()).toBe(impl); }); }); });