mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-10 02:33:04 +02:00
Test fix
This commit is contained in:
@@ -150,35 +150,31 @@ describe('usePushSubscription', () => {
|
|||||||
expect(result.current.allSubscriptions).toEqual([]);
|
expect(result.current.allSubscriptions).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(
|
it('times out and shows a toast when service worker never activates', async () => {
|
||||||
'times out and shows a toast when service worker never activates',
|
// Replace serviceWorker.ready with a promise that never resolves
|
||||||
async () => {
|
Object.defineProperty(navigator, 'serviceWorker', {
|
||||||
// Replace serviceWorker.ready with a promise that never resolves
|
configurable: true,
|
||||||
Object.defineProperty(navigator, 'serviceWorker', {
|
value: {
|
||||||
configurable: true,
|
ready: new Promise(() => {}),
|
||||||
value: {
|
},
|
||||||
ready: new Promise(() => {}),
|
});
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { result } = renderHook(() => usePushSubscription());
|
const { result } = renderHook(() => usePushSubscription());
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(result.current.isSupported).toBe(true);
|
expect(result.current.isSupported).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// subscribe() will hang on serviceWorker.ready, then the 1s timeout fires
|
// subscribe() will hang on serviceWorker.ready, then the 1s timeout fires
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
await result.current.subscribe();
|
await result.current.subscribe();
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.current.loading).toBe(false);
|
expect(result.current.loading).toBe(false);
|
||||||
expect(mocks.toast.error).toHaveBeenCalledWith('Failed to enable push notifications', {
|
expect(mocks.toast.error).toHaveBeenCalledWith('Failed to enable push notifications', {
|
||||||
description: expect.stringContaining('trusted TLS certificate for service workers'),
|
description: expect.stringContaining('trusted TLS certificate for service workers'),
|
||||||
});
|
});
|
||||||
},
|
}, 5_000);
|
||||||
5_000
|
|
||||||
);
|
|
||||||
|
|
||||||
it('recreates a stale browser subscription when the server VAPID key changed', async () => {
|
it('recreates a stale browser subscription when the server VAPID key changed', async () => {
|
||||||
const oldSubscription = activeSubscription;
|
const oldSubscription = activeSubscription;
|
||||||
|
|||||||
Reference in New Issue
Block a user