11import { module , test } from 'qunit' ;
22import { setupApplicationTest } from 'ember-qunit' ;
3+ import sinon from 'sinon' ;
34
45module ( 'Acceptance | Simple Acceptance Test' , ( hooks ) => {
56 setupApplicationTest ( hooks ) ;
@@ -48,6 +49,8 @@ module('Acceptance | Simple Acceptance Test', (hooks) => {
4849 const registrations =
4950 await window . navigator . serviceWorker . getRegistrations ( ) ;
5051
52+ console . log ( 'ave4r si ' + JSON . stringify ( registrations ) ) ;
53+
5154 assert . ok ( registrations . length ) ;
5255 } ) ;
5356
@@ -74,6 +77,39 @@ module('Acceptance | Simple Acceptance Test', (hooks) => {
7477 assert . notOk ( registrations . length ) ;
7578 } ) ;
7679
80+ test ( 'it unregisters sw but fails' , async function ( assert ) {
81+ await this . swService . register ( 'sw.js' ) ;
82+
83+ const registrations = await this . swService . sw . getRegistrations ( ) ;
84+ const stubs = registrations . map ( ( reg ) => {
85+ return sinon . stub ( reg , 'unregister' ) . callsFake ( ( ) => {
86+ return Promise . resolve ( false ) ;
87+ } ) ;
88+ } ) ;
89+
90+ const stubLog = sinon . stub ( this . swService , '_log' ) ;
91+
92+ assert . deepEqual (
93+ this . events ,
94+ [ 'registrationComplete' ] ,
95+ 'Event triggered: registrationComplete'
96+ ) ;
97+
98+ await this . swService . unregisterAll ( ) ;
99+
100+ assert . ok ( stubLog . called ) ;
101+ assert . ok ( registrations . length ) ;
102+
103+ assert . deepEqual (
104+ this . events ,
105+ [ 'registrationComplete' , 'unregistrationComplete' ] ,
106+ 'Service worker does not exists'
107+ ) ;
108+
109+ stubs . forEach ( ( stubReg ) => stubReg . restore ( ) ) ;
110+ stubLog . restore ( ) ;
111+ } ) ;
112+
77113 test . skip ( 'it triggers "update" event on sw response' , async function ( assert ) {
78114 const _reload = window . location . reload ;
79115 let called = 0 ;
0 commit comments