@@ -92,8 +92,7 @@ describe('AngularFirestoreCollection', () => {
92
92
expect ( data . length ) . toEqual ( ITEMS ) ;
93
93
pricefilter$ . next ( - 1 ) ;
94
94
}
95
- // on the second round, make sure the array is still the same
96
- // length but the updated item is now modified
95
+ // on the second round, we should have filtered out everything
97
96
if ( count === 2 ) {
98
97
expect ( data . length ) . toEqual ( 0 ) ;
99
98
sub . unsubscribe ( ) ;
@@ -193,6 +192,35 @@ describe('AngularFirestoreCollection', () => {
193
192
delayAdd ( stocks , nextId , { price : 2 } ) ;
194
193
} ) ;
195
194
195
+ it ( 'should be able to filter snapshotChanges() types - added/modified' , async ( done ) => {
196
+ const ITEMS = 10 ;
197
+ let { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
198
+ const nextId = ref . doc ( 'a' ) . id ;
199
+ let count = 0 ;
200
+
201
+ const sub = stocks . snapshotChanges ( [ 'added' , 'modified' ] ) . skip ( 1 ) . take ( 2 ) . subscribe ( data => {
202
+ count += 1 ;
203
+ if ( count == 1 ) {
204
+ const change = data . filter ( x => x . payload . doc . id === nextId ) [ 0 ] ;
205
+ expect ( data . length ) . toEqual ( ITEMS + 1 ) ;
206
+ expect ( change . payload . doc . data ( ) . price ) . toEqual ( 2 ) ;
207
+ expect ( change . type ) . toEqual ( 'added' ) ;
208
+ delayUpdate ( stocks , names [ 0 ] , { price : 2 } ) ;
209
+ }
210
+ if ( count == 2 ) {
211
+ const change = data . filter ( x => x . payload . doc . id === names [ 0 ] ) [ 0 ] ;
212
+ expect ( data . length ) . toEqual ( ITEMS + 1 ) ;
213
+ expect ( change . payload . doc . data ( ) . price ) . toEqual ( 2 ) ;
214
+ expect ( change . type ) . toEqual ( 'modified' ) ;
215
+ }
216
+ } ) . add ( ( ) => {
217
+ deleteThemAll ( names , ref ) . then ( done ) . catch ( done . fail ) ;
218
+ } ) ;
219
+
220
+ names = names . concat ( [ nextId ] ) ;
221
+ delayAdd ( stocks , nextId , { price : 2 } ) ;
222
+ } ) ;
223
+
196
224
it ( 'should be able to filter snapshotChanges() types - removed' , async ( done ) => {
197
225
const ITEMS = 10 ;
198
226
const { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
0 commit comments