import type { IRefreshOnMountStore } from '../query.api'; import { refreshStoresOnMount } from '../refresh-stores-on-mount'; describe('refreshStoresOnMount', () => { const createMockStore = (): IRefreshOnMountStore => ({ refreshOnMount: jest.fn(), refreshStoresOnMount: jest.fn(), }); it('should refresh queries', () => { const q1 = createMockStore(); const q2 = createMockStore(); const handler = refreshStoresOnMount({ queries: [q1, q2] }); handler(); expect(q1.refreshOnMount).toHaveBeenCalled(); expect(q2.refreshOnMount).toHaveBeenCalled(); }); it('should refresh stores', () => { const s1 = createMockStore(); const s2 = createMockStore(); const handler = refreshStoresOnMount({ stores: [s1, s2] }); handler(); expect(s1.refreshOnMount).toHaveBeenCalled(); expect(s2.refreshOnMount).toHaveBeenCalled(); }); it('should refresh both queries and stores', () => { const q1 = createMockStore(); const s1 = createMockStore(); const handler = refreshStoresOnMount({ queries: [q1], stores: [s1] }); handler(); expect(q1.refreshOnMount).toHaveBeenCalled(); expect(s1.refreshOnMount).toHaveBeenCalled(); }); it('should handle undefined entries in arrays', () => { const q1 = createMockStore(); const handler = refreshStoresOnMount({ queries: [q1, undefined], stores: [undefined], }); expect(() => handler()).not.toThrow(); expect(q1.refreshOnMount).toHaveBeenCalled(); }); it('should handle empty options', () => { const handler = refreshStoresOnMount({}); expect(() => handler()).not.toThrow(); }); });