@@ -39,6 +39,7 @@ import {
39
39
} from '../interfaces/internal-message-payload' ;
40
40
import {
41
41
NotificationEvent ,
42
+ PushSubscriptionChangeEvent ,
42
43
ServiceWorkerGlobalScope ,
43
44
ServiceWorkerGlobalScopeEventMap ,
44
45
WindowClient
@@ -427,9 +428,9 @@ describe('SwController', () => {
427
428
428
429
describe ( 'onSubChange' , ( ) => {
429
430
it ( 'calls deleteToken if there is no new subscription' , async ( ) => {
430
- const event = makeEvent ( 'pushsubscriptionchange' , {
431
+ const event = makeFakePushSubscriptionChangeEvent ( {
431
432
oldSubscription : new FakePushSubscription ( ) ,
432
- newSubscription : undefined
433
+ newSubscription : null
433
434
} ) ;
434
435
435
436
await callEventListener ( event ) ;
@@ -439,7 +440,7 @@ describe('SwController', () => {
439
440
} ) ;
440
441
441
442
it ( 'calls deleteToken and getToken if subscription changed' , async ( ) => {
442
- const event = makeEvent ( 'pushsubscriptionchange' , {
443
+ const event = makeFakePushSubscriptionChangeEvent ( {
443
444
oldSubscription : new FakePushSubscription ( ) ,
444
445
newSubscription : new FakePushSubscription ( )
445
446
} ) ;
@@ -474,3 +475,12 @@ function makeEvent<K extends keyof ServiceWorkerGlobalScopeEventMap>(
474
475
Object . assign ( event , data ) ;
475
476
return event as unknown as ServiceWorkerGlobalScopeEventMap [ K ] ;
476
477
}
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