diff --git a/packages/renderer/src/stores/event-store.spec.ts b/packages/renderer/src/stores/event-store.spec.ts index 75e046a1f0b96..f175008f13c48 100644 --- a/packages/renderer/src/stores/event-store.spec.ts +++ b/packages/renderer/src/stores/event-store.spec.ts @@ -196,6 +196,42 @@ test('should call fetch with arguments', async () => { expect(updater).toHaveBeenCalledWith(...args); }); +test('should call fetch method using window event and object argument', async () => { + const myStoreInfo: Writable = writable([]); + const checkForUpdateMock = vi.fn(); + + const windowEventName = 'my-custom-event'; + const updater = vi.fn(); + + // return true to trigger the update + checkForUpdateMock.mockResolvedValue(true); + + const eventStore = new TestEventStore('my-test', myStoreInfo, checkForUpdateMock, [windowEventName], [], updater); + + // callbacks are empty + expect(callbacks.size).toBe(0); + + // now call the setup + eventStore.setup(); + + // check we have callbacks + expect(callbacks.size).toBe(1); + + // now we call the listener + const callback = callbacks.get(windowEventName); + expect(callback).toBeDefined(); + + const myCustomTypeInfo: MyCustomTypeInfo = { + name: 'my-custom-type', + }; + updater.mockResolvedValue([myCustomTypeInfo]); + + await callback({}); + + // check the updater is called + expect(updater).toHaveBeenCalledWith({}); +}); + test('Check debounce', async () => { const myStoreInfo: Writable = writable([]); const checkForUpdateMock = vi.fn(); diff --git a/packages/renderer/src/stores/event-store.ts b/packages/renderer/src/stores/event-store.ts index 51edf060ac185..0c9db83eaef4d 100644 --- a/packages/renderer/src/stores/event-store.ts +++ b/packages/renderer/src/stores/event-store.ts @@ -115,7 +115,11 @@ export class EventStore { const before = performance.now(); const customArgs = []; if (args) { - customArgs.push(...args); + if (Array.isArray(args)) { + customArgs.push(...args); + } else { + customArgs.push(args); + } } const result = await this.updater(...customArgs); const after = performance.now();