diff --git a/types/service-worker-mock/index.d.ts b/types/service-worker-mock/index.d.ts index eb844d1d45..b68799aef8 100644 --- a/types/service-worker-mock/index.d.ts +++ b/types/service-worker-mock/index.d.ts @@ -42,6 +42,10 @@ declare global { * Used to trigger active listeners. */ function trigger(type: keyof ServiceWorkerGlobalScopeEventMap): Promise; + function trigger(name: 'fetch', request: string | Request): Promise; + function trigger(name: 'notificationclick' | 'notificationclose', args: Notification): Promise; + function trigger(name: 'push', args: Partial): Promise; + function trigger(name: 'message', args: Partial): Promise; /** * Used to generate a snapshot of the service worker internals. diff --git a/types/service-worker-mock/service-worker-mock-tests.ts b/types/service-worker-mock/service-worker-mock-tests.ts index 2e3f2fd6ee..2784b56521 100644 --- a/types/service-worker-mock/service-worker-mock-tests.ts +++ b/types/service-worker-mock/service-worker-mock-tests.ts @@ -8,6 +8,18 @@ trigger('install'); mock.trigger('install'); trigger('fetch'); mock.trigger('fetch'); +trigger('fetch', 'https://example.com'); +mock.trigger('fetch', 'https://example.com'); +trigger('fetch', new Request('https://example.com')); +mock.trigger('fetch', new Request('https://example.com')); +trigger('notificationclick', new Notification('Hello!')); +mock.trigger('notificationclick', new Notification('Hello!')); +trigger('notificationclose', new Notification('Hello!')); +mock.trigger('notificationclose', new Notification('Hello!')); +trigger('push', { data: null }); +mock.trigger('push', { data: null }); +trigger('message', { source: null }); +mock.trigger('message', { source: null }); const emitFetch = listeners.get('fetch') as EventListener; emitFetch(new Event('fetch'));