@@ -7,6 +7,7 @@ import { QueryFn } from '../interfaces';
77
88import * as firebase from 'firebase/app' ;
99import { Observable } from 'rxjs/Observable' ;
10+ import { BehaviorSubject } from 'rxjs/BehaviorSubject' ;
1011import { of } from 'rxjs/observable/of' ;
1112import { Subscription } from 'rxjs/Subscription' ;
1213import 'rxjs/add/operator/skip' ;
@@ -73,6 +74,34 @@ describe('AngularFirestoreCollection', () => {
7374 } ) ;
7475
7576 } ) ;
77+
78+ it ( 'should handle dynamic queries that return empty sets' , async ( done ) => {
79+ const ITEMS = 10 ;
80+ let count = 0 ;
81+ let firstIndex = 0 ;
82+ let pricefilter$ = new BehaviorSubject < number | null > ( null ) ;
83+ const randomCollectionName = randomName ( afs . firestore ) ;
84+ const ref = afs . firestore . collection ( `${ randomCollectionName } ` ) ;
85+ let names = await createRandomStocks ( afs . firestore , ref , ITEMS ) ;
86+ const sub = pricefilter$ . switchMap ( price => {
87+ return afs . collection ( randomCollectionName , ref => price ? ref . where ( 'price' , '==' , price ) : ref ) . valueChanges ( )
88+ } ) . subscribe ( data => {
89+ count = count + 1 ;
90+ // the first time should all be 'added'
91+ if ( count === 1 ) {
92+ expect ( data . length ) . toEqual ( ITEMS ) ;
93+ pricefilter$ . next ( - 1 ) ;
94+ }
95+ // on the second round, make sure the array is still the same
96+ // length but the updated item is now modified
97+ if ( count === 2 ) {
98+ expect ( data . length ) . toEqual ( 0 ) ;
99+ sub . unsubscribe ( ) ;
100+ deleteThemAll ( names , ref ) . then ( done ) . catch ( done . fail ) ;
101+ }
102+ } ) ;
103+ } ) ;
104+
76105 } ) ;
77106
78107 describe ( 'snapshotChanges()' , ( ) => {
@@ -83,7 +112,6 @@ describe('AngularFirestoreCollection', () => {
83112 const { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
84113 const sub = stocks . snapshotChanges ( ) . subscribe ( data => {
85114 const ids = data . map ( d => d . payload . doc . id ) ;
86- debugger ;
87115 count = count + 1 ;
88116 // the first time should all be 'added'
89117 if ( count === 1 ) {
@@ -133,7 +161,7 @@ describe('AngularFirestoreCollection', () => {
133161 const ITEMS = 10 ;
134162 const { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
135163
136- const sub = stocks . snapshotChanges ( [ 'modified' ] ) . subscribe ( data => {
164+ const sub = stocks . snapshotChanges ( [ 'modified' ] ) . skip ( 1 ) . subscribe ( data => {
137165 sub . unsubscribe ( ) ;
138166 const change = data . filter ( x => x . payload . doc . id === names [ 0 ] ) [ 0 ] ;
139167 expect ( data . length ) . toEqual ( 1 ) ;
0 commit comments