@@ -7,6 +7,7 @@ import { QueryFn } from '../interfaces';
7
7
8
8
import * as firebase from 'firebase/app' ;
9
9
import { Observable } from 'rxjs/Observable' ;
10
+ import { BehaviorSubject } from 'rxjs/BehaviorSubject' ;
10
11
import { of } from 'rxjs/observable/of' ;
11
12
import { Subscription } from 'rxjs/Subscription' ;
12
13
import 'rxjs/add/operator/skip' ;
@@ -73,6 +74,34 @@ describe('AngularFirestoreCollection', () => {
73
74
} ) ;
74
75
75
76
} ) ;
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
+
76
105
} ) ;
77
106
78
107
describe ( 'snapshotChanges()' , ( ) => {
@@ -83,7 +112,6 @@ describe('AngularFirestoreCollection', () => {
83
112
const { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
84
113
const sub = stocks . snapshotChanges ( ) . subscribe ( data => {
85
114
const ids = data . map ( d => d . payload . doc . id ) ;
86
- debugger ;
87
115
count = count + 1 ;
88
116
// the first time should all be 'added'
89
117
if ( count === 1 ) {
@@ -133,7 +161,7 @@ describe('AngularFirestoreCollection', () => {
133
161
const ITEMS = 10 ;
134
162
const { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
135
163
136
- const sub = stocks . snapshotChanges ( [ 'modified' ] ) . subscribe ( data => {
164
+ const sub = stocks . snapshotChanges ( [ 'modified' ] ) . skip ( 1 ) . subscribe ( data => {
137
165
sub . unsubscribe ( ) ;
138
166
const change = data . filter ( x => x . payload . doc . id === names [ 0 ] ) [ 0 ] ;
139
167
expect ( data . length ) . toEqual ( 1 ) ;
0 commit comments