@@ -125,18 +125,21 @@ describe('firestore.QuerySnapshot', function () {
125
125
126
126
it ( 'returns an array of DocumentChange instances' , async function ( ) {
127
127
const colRef = firebase . firestore ( ) . collection ( COLLECTION ) ;
128
- colRef . add ( { } ) ;
128
+ await colRef . add ( { } ) ;
129
129
const snapshot = await colRef . limit ( 1 ) . get ( ) ;
130
130
const changes = snapshot . docChanges ( ) ;
131
131
changes . should . be . Array ( ) ;
132
132
changes . length . should . be . eql ( 1 ) ;
133
133
changes [ 0 ] . constructor . name . should . eql ( 'FirestoreDocumentChange' ) ;
134
134
} ) ;
135
135
136
- // TODO: fixme @ehesp - flaky test: `AssertionError: expected 3 to equal 1` on line 155
137
- xit ( 'returns the correct number of document changes if listening to metadata changes' , async function ( ) {
136
+ it ( 'returns the correct number of document changes if listening to metadata changes' , async function ( ) {
138
137
const callback = sinon . spy ( ) ;
139
- const colRef = firebase . firestore ( ) . collection ( 'v6/metadatachanges/true-true' ) ;
138
+ const colRef = firebase
139
+ . firestore ( )
140
+ // Firestore caches aggressively, even if you wipe the emulator, local documents are cached
141
+ // between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
142
+ . collection ( `${ COLLECTION } /${ Utils . randString ( 12 , '#aA' ) } /metadatachanges-true-true` ) ;
140
143
const unsub = colRef . onSnapshot ( { includeMetadataChanges : true } , callback ) ;
141
144
await colRef . add ( { foo : 'bar' } ) ;
142
145
await Utils . spyToBeCalledTimesAsync ( callback , 3 ) ;
@@ -151,10 +154,13 @@ describe('firestore.QuerySnapshot', function () {
151
154
snap3 . docChanges ( { includeMetadataChanges : true } ) . length . should . be . eql ( 1 ) ;
152
155
} ) ;
153
156
154
- // TODO: fixme @ehesp - flaky test: `AssertionError: expected 5 to equal 1`
155
- xit ( 'returns the correct number of document changes if listening to metadata changes, but not including them in docChanges' , async function ( ) {
157
+ it ( 'returns the correct number of document changes if listening to metadata changes, but not including them in docChanges' , async function ( ) {
156
158
const callback = sinon . spy ( ) ;
157
- const colRef = firebase . firestore ( ) . collection ( 'v6/metadatachanges/true-false' ) ;
159
+ const colRef = firebase
160
+ . firestore ( )
161
+ // Firestore caches aggressively, even if you wipe the emulator, local documents are cached
162
+ // between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
163
+ . collection ( `${ COLLECTION } /${ Utils . randString ( 12 , '#aA' ) } /metadatachanges-true-false` ) ;
158
164
const unsub = colRef . onSnapshot ( { includeMetadataChanges : true } , callback ) ;
159
165
await colRef . add ( { foo : 'bar' } ) ;
160
166
await Utils . spyToBeCalledTimesAsync ( callback , 3 ) ;
@@ -173,7 +179,8 @@ describe('firestore.QuerySnapshot', function () {
173
179
describe ( 'forEach()' , function ( ) {
174
180
it ( 'throws if callback is not a function' , async function ( ) {
175
181
try {
176
- const colRef = firebase . firestore ( ) . collection ( COLLECTION ) ;
182
+ const colRef = firebase . firestore ( ) . collection ( `${ COLLECTION } /callbacks/nonfunction` ) ;
183
+ await colRef . add ( { } ) ;
177
184
const snapshot = await colRef . limit ( 1 ) . get ( ) ;
178
185
snapshot . forEach ( 123 ) ;
179
186
return Promise . reject ( new Error ( 'Did not throw an Error.' ) ) ;
@@ -184,13 +191,14 @@ describe('firestore.QuerySnapshot', function () {
184
191
} ) ;
185
192
186
193
it ( 'calls back a function' , async function ( ) {
187
- const colRef = firebase . firestore ( ) . collection ( COLLECTION ) ;
188
- colRef . add ( { } ) ;
189
- colRef . add ( { } ) ;
194
+ const colRef = firebase . firestore ( ) . collection ( ` ${ COLLECTION } /callbacks/function` ) ;
195
+ await colRef . add ( { } ) ;
196
+ await colRef . add ( { } ) ;
190
197
const snapshot = await colRef . limit ( 2 ) . get ( ) ;
191
198
const callback = sinon . spy ( ) ;
192
199
snapshot . forEach . should . be . Function ( ) ;
193
200
snapshot . forEach ( callback ) ;
201
+ await Utils . spyToBeCalledTimesAsync ( callback , 2 , 20000 ) ;
194
202
callback . should . be . calledTwice ( ) ;
195
203
callback . args [ 0 ] [ 0 ] . constructor . name . should . eql ( 'FirestoreDocumentSnapshot' ) ;
196
204
callback . args [ 0 ] [ 1 ] . should . be . Number ( ) ;
@@ -199,8 +207,8 @@ describe('firestore.QuerySnapshot', function () {
199
207
} ) ;
200
208
201
209
it ( 'provides context to the callback' , async function ( ) {
202
- const colRef = firebase . firestore ( ) . collection ( COLLECTION ) ;
203
- colRef . add ( { } ) ;
210
+ const colRef = firebase . firestore ( ) . collection ( ` ${ COLLECTION } /callbacks/function-context` ) ;
211
+ await colRef . add ( { } ) ;
204
212
const snapshot = await colRef . limit ( 1 ) . get ( ) ;
205
213
const callback = sinon . spy ( ) ;
206
214
snapshot . forEach . should . be . Function ( ) ;
0 commit comments