@@ -309,3 +309,49 @@ test('unbinds when a ref is replaced', async () => {
309309 cSpy . mockRestore ( )
310310 dSpy . mockRestore ( )
311311} )
312+
313+ test ( 'unbinds removed properties' , async ( ) => {
314+ const a = db . collection ( ) . doc ( )
315+ const b = db . collection ( ) . doc ( )
316+ const unbindSpy = spyUnbind ( a )
317+ const callbackSpy = spyOnSnapshotCallback ( a )
318+ const onSnapshotSpy = spyOnSnapshot ( a )
319+
320+ const item = db . collection ( ) . doc ( )
321+ await a . update ( { isA : true } )
322+ await b . update ( { isB : true } )
323+ await item . update ( { a } )
324+
325+ expect ( unbindSpy ) . toHaveBeenCalledTimes ( 0 )
326+ expect ( callbackSpy ) . toHaveBeenCalledTimes ( 0 )
327+ expect ( onSnapshotSpy ) . toHaveBeenCalledTimes ( 0 )
328+ await vm . $bind ( 'item' , item )
329+ expect ( vm . item ) . toEqual ( {
330+ a : {
331+ isA : true
332+ }
333+ } )
334+
335+ expect ( unbindSpy ) . toHaveBeenCalledTimes ( 0 )
336+ expect ( callbackSpy ) . toHaveBeenCalledTimes ( 1 )
337+ expect ( onSnapshotSpy ) . toHaveBeenCalledTimes ( 1 )
338+
339+ await item . set ( { b } )
340+ await a . update ( { newA : true } )
341+ // NOTE see #1
342+ await delay ( 5 )
343+
344+ expect ( vm . item ) . toEqual ( {
345+ b : {
346+ isB : true
347+ }
348+ } )
349+
350+ expect ( unbindSpy ) . toHaveBeenCalledTimes ( 1 )
351+ expect ( callbackSpy ) . toHaveBeenCalledTimes ( 1 )
352+ expect ( onSnapshotSpy ) . toHaveBeenCalledTimes ( 1 )
353+
354+ unbindSpy . mockRestore ( )
355+ callbackSpy . mockRestore ( )
356+ onSnapshotSpy . mockRestore ( )
357+ } )
0 commit comments