Skip to content

Commit bde166b

Browse files
committed
Fix typing issue in messaging
1 parent c949c8e commit bde166b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/messaging/src/listeners/sw-listeners.test.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
} from '../interfaces/internal-message-payload';
4040
import {
4141
NotificationEvent,
42+
PushSubscriptionChangeEvent,
4243
ServiceWorkerGlobalScope,
4344
ServiceWorkerGlobalScopeEventMap,
4445
WindowClient
@@ -427,9 +428,9 @@ describe('SwController', () => {
427428

428429
describe('onSubChange', () => {
429430
it('calls deleteToken if there is no new subscription', async () => {
430-
const event = makeEvent('pushsubscriptionchange', {
431+
const event = makeFakePushSubscriptionChangeEvent({
431432
oldSubscription: new FakePushSubscription(),
432-
newSubscription: undefined
433+
newSubscription: null
433434
});
434435

435436
await callEventListener(event);
@@ -439,7 +440,7 @@ describe('SwController', () => {
439440
});
440441

441442
it('calls deleteToken and getToken if subscription changed', async () => {
442-
const event = makeEvent('pushsubscriptionchange', {
443+
const event = makeFakePushSubscriptionChangeEvent({
443444
oldSubscription: new FakePushSubscription(),
444445
newSubscription: new FakePushSubscription()
445446
});
@@ -474,3 +475,12 @@ function makeEvent<K extends keyof ServiceWorkerGlobalScopeEventMap>(
474475
Object.assign(event, data);
475476
return event as unknown as ServiceWorkerGlobalScopeEventMap[K];
476477
}
478+
479+
function makeFakePushSubscriptionChangeEvent(data: {
480+
newSubscription: PushSubscription | null,
481+
oldSubscription: PushSubscription | null
482+
}): PushSubscriptionChangeEvent {
483+
const event = new FakeEvent('pushsubscriptionchange');
484+
Object.assign(event, data);
485+
return event as unknown as PushSubscriptionChangeEvent;
486+
}

0 commit comments

Comments
 (0)