@@ -131,6 +131,33 @@ describe("#docChanges()", () => {
131131 } ) ;
132132 } ) ;
133133
134+ it ( "list docs as removed even when they are not the last in the list" , ( ) => {
135+ const docs = [
136+ new MockQueryDocumentSnapshot ( query . firestore . doc ( "foo/0" ) , { } ) ,
137+ new MockQueryDocumentSnapshot ( query . firestore . doc ( "foo/1" ) , { } ) ,
138+ new MockQueryDocumentSnapshot ( query . firestore . doc ( "foo/2" ) , { } ) ,
139+ new MockQueryDocumentSnapshot ( query . firestore . doc ( "foo/3" ) , { } ) ,
140+ ] ;
141+
142+ createSnapshot ( docs ) ;
143+ const snapshot2 = createSnapshot ( [ docs [ 0 ] , docs [ 1 ] , docs [ 3 ] ] ) ;
144+
145+ const changes = snapshot2 . docChanges ( ) ;
146+ expect ( changes ) . toHaveLength ( 2 ) ;
147+ expect ( changes ) . toContainEqual ( {
148+ type : "removed" ,
149+ oldIndex : 2 ,
150+ newIndex : - 1 ,
151+ doc : docs [ 2 ] ,
152+ } ) ;
153+ expect ( changes ) . toContainEqual ( {
154+ type : "modified" ,
155+ oldIndex : 3 ,
156+ newIndex : 2 ,
157+ doc : docs [ 3 ] ,
158+ } ) ;
159+ } ) ;
160+
134161 it ( "lists docs as added when they are not in the previous snapshot" , async ( ) => {
135162 const docs = [
136163 new MockQueryDocumentSnapshot ( query . firestore . doc ( "foo/bar" ) , { } ) ,
@@ -151,6 +178,25 @@ describe("#docChanges()", () => {
151178 } ) ;
152179} ) ;
153180
181+ it ( "list changes that happen across different collections" , ( ) => {
182+ const docs = [
183+ new MockQueryDocumentSnapshot ( query . firestore . doc ( "foo/a" ) , { } ) ,
184+ new MockQueryDocumentSnapshot ( query . firestore . doc ( "bar/a" ) , { } ) ,
185+ ] ;
186+
187+ createSnapshot ( docs ) ;
188+ const snapshot2 = createSnapshot ( [ docs [ 0 ] ] ) ;
189+
190+ const changes = snapshot2 . docChanges ( ) ;
191+ expect ( changes ) . toHaveLength ( 1 ) ;
192+ expect ( changes ) . toContainEqual ( {
193+ type : "removed" ,
194+ oldIndex : 1 ,
195+ newIndex : - 1 ,
196+ doc : docs [ 1 ] ,
197+ } ) ;
198+ } ) ;
199+
154200describe ( "#forEach()" , ( ) => {
155201 it ( "iterates thru #docs" , ( ) => {
156202 const callback = jest . fn ( ) ;
0 commit comments