@@ -240,18 +240,22 @@ describe('TranslationContext', () => {
240240
241241 let unsubscribeSpy ;
242242 let listenersAfterInitialMount ;
243+ const initSpy = jest . spyOn ( chatClientWithUser . offlineDb . syncManager , 'init' ) ;
243244
244245 await waitFor ( ( ) => {
245246 // the unsubscribe fn changes during init(), so we keep a reference to the spy
246- unsubscribeSpy = jest . spyOn ( DBSyncManager . connectionChangedListener , 'unsubscribe' ) ;
247+ unsubscribeSpy = jest . spyOn (
248+ chatClientWithUser . offlineDb . syncManager . connectionChangedListener ,
249+ 'unsubscribe' ,
250+ ) ;
247251 listenersAfterInitialMount = chatClientWithUser . listeners [ 'connection.changed' ] ;
248252 } ) ;
249253
250254 // remount
251255 rerender ( < Chat client = { chatClientWithUser } enableOfflineSupport key = { 2 } /> ) ;
252256
253257 await waitFor ( ( ) => {
254- expect ( DBSyncManager . init ) . toHaveBeenCalledTimes ( 2 ) ;
258+ expect ( initSpy ) . toHaveBeenCalledTimes ( 2 ) ;
255259 expect ( unsubscribeSpy ) . toHaveBeenCalledTimes ( 2 ) ;
256260 expect ( chatClientWithUser . listeners [ 'connection.changed' ] . length ) . toBe (
257261 listenersAfterInitialMount . length ,
@@ -267,10 +271,14 @@ describe('TranslationContext', () => {
267271
268272 let unsubscribeSpy ;
269273 let listenersAfterInitialMount ;
274+ const initSpy = jest . spyOn ( chatClientWithUser . offlineDb . syncManager , 'init' ) ;
270275
271276 await waitFor ( ( ) => {
272277 // the unsubscribe fn changes during init(), so we keep a reference to the spy
273- unsubscribeSpy = jest . spyOn ( DBSyncManager . connectionChangedListener , 'unsubscribe' ) ;
278+ unsubscribeSpy = jest . spyOn (
279+ chatClientWithUser . offlineDb . syncManager . connectionChangedListener ,
280+ 'unsubscribe' ,
281+ ) ;
274282 listenersAfterInitialMount = chatClientWithUser . listeners [ 'connection.changed' ] ;
275283 } ) ;
276284
@@ -282,7 +290,7 @@ describe('TranslationContext', () => {
282290 rerender ( < Chat client = { chatClientWithUser } enableOfflineSupport /> ) ;
283291
284292 await waitFor ( ( ) => {
285- expect ( DBSyncManager . init ) . toHaveBeenCalledTimes ( 2 ) ;
293+ expect ( initSpy ) . toHaveBeenCalledTimes ( 2 ) ;
286294 expect ( unsubscribeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
287295 expect ( chatClientWithUser . listeners [ 'connection.changed' ] . length ) . toBe (
288296 listenersAfterInitialMount . length ,
@@ -297,9 +305,14 @@ describe('TranslationContext', () => {
297305 const { rerender } = render ( < Chat client = { chatClientWithUser } enableOfflineSupport /> ) ;
298306
299307 let unsubscribeSpy ;
308+ const initSpy = jest . spyOn ( chatClientWithUser . offlineDb . syncManager , 'init' ) ;
309+
300310 await waitFor ( ( ) => {
301311 // the unsubscribe fn changes during init(), so we keep a reference to the spy
302- unsubscribeSpy = jest . spyOn ( DBSyncManager . connectionChangedListener , 'unsubscribe' ) ;
312+ unsubscribeSpy = jest . spyOn (
313+ chatClientWithUser . offlineDb . syncManager . connectionChangedListener ,
314+ 'unsubscribe' ,
315+ ) ;
303316 } ) ;
304317
305318 const listenersAfterInitialMount = chatClientWithUser . listeners [ 'connection.changed' ] ;
@@ -308,8 +321,8 @@ describe('TranslationContext', () => {
308321 rerender ( < Chat client = { chatClientWithUser } enableOfflineSupport /> ) ;
309322
310323 await waitFor ( ( ) => {
311- expect ( DBSyncManager . init ) . toHaveBeenCalledTimes ( 1 ) ;
312- expect ( unsubscribeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
324+ expect ( initSpy ) . toHaveBeenCalledTimes ( 1 ) ;
325+ expect ( unsubscribeSpy ) . toHaveBeenCalledTimes ( 0 ) ;
313326 expect ( chatClientWithUser . listeners [ 'connection.changed' ] . length ) . toBe (
314327 listenersAfterInitialMount . length ,
315328 ) ;
0 commit comments