Skip to content

Commit

Permalink
fix: handle single non-spread arguments
Browse files Browse the repository at this point in the history
fixes podman-desktop#3635 (review)
Signed-off-by: Florent Benoit <[email protected]>
  • Loading branch information
benoitf authored and mairin committed Aug 29, 2023
1 parent 31a2626 commit e0ac572
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 36 additions & 0 deletions packages/renderer/src/stores/event-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyCustomTypeInfo[]> = 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<MyCustomTypeInfo[]> = writable([]);
const checkForUpdateMock = vi.fn();
Expand Down
6 changes: 5 additions & 1 deletion packages/renderer/src/stores/event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ export class EventStore<T> {
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();
Expand Down

0 comments on commit e0ac572

Please sign in to comment.