@@ -202,13 +202,17 @@ describe('firestore()', function () {
202202 describe ( 'serverTimestampBehavior' , function ( ) {
203203 it ( "handles 'estimate'" , async function ( ) {
204204 firebase . firestore ( ) . settings ( { serverTimestampBehavior : 'estimate' } ) ;
205- const ref = firebase . firestore ( ) . doc ( `${ COLLECTION } /getData ` ) ;
205+ const ref = firebase . firestore ( ) . doc ( `${ COLLECTION } /serverTimestampEstimate ` ) ;
206206
207207 const promise = new Promise ( ( resolve , reject ) => {
208208 const subscription = ref . onSnapshot ( snapshot => {
209- should ( snapshot . get ( 'timestamp' ) ) . be . an . instanceOf ( firebase . firestore . Timestamp ) ;
210- subscription ( ) ;
211- resolve ( ) ;
209+ try {
210+ should ( snapshot . get ( 'timestamp' ) ) . be . an . instanceOf ( firebase . firestore . Timestamp ) ;
211+ subscription ( ) ;
212+ resolve ( ) ;
213+ } catch ( e ) {
214+ reject ( e ) ;
215+ }
212216 } , reject ) ;
213217 } ) ;
214218
@@ -218,28 +222,33 @@ describe('firestore()', function () {
218222 } ) ;
219223 it ( "handles 'previous'" , async function ( ) {
220224 firebase . firestore ( ) . settings ( { serverTimestampBehavior : 'previous' } ) ;
221- const ref = firebase . firestore ( ) . doc ( `${ COLLECTION } /getData ` ) ;
225+ const ref = firebase . firestore ( ) . doc ( `${ COLLECTION } /serverTimestampPrevious ` ) ;
222226
223227 const promise = new Promise ( ( resolve , reject ) => {
224228 let counter = 0 ;
225229 let previous = null ;
226230 const subscription = ref . onSnapshot ( snapshot => {
227- switch ( counter ++ ) {
228- case 0 :
229- break ;
230- case 1 :
231- should ( snapshot . get ( 'timestamp' ) ) . be . an . instanceOf ( firebase . firestore . Timestamp ) ;
232- break ;
233- case 2 :
234- should ( snapshot . get ( 'timestamp' ) ) . be . an . instanceOf ( firebase . firestore . Timestamp ) ;
235- should ( snapshot . get ( 'timestamp' ) . isEqual ( previous . get ( 'timestamp' ) ) ) . equal ( true ) ;
236- break ;
237- case 3 :
238- should ( snapshot . get ( 'timestamp' ) ) . be . an . instanceOf ( firebase . firestore . Timestamp ) ;
239- should ( snapshot . get ( 'timestamp' ) . isEqual ( previous . get ( 'timestamp' ) ) ) . equal ( false ) ;
240- subscription ( ) ;
241- resolve ( ) ;
242- break ;
231+ try {
232+ switch ( counter ++ ) {
233+ case 0 :
234+ should ( snapshot . get ( 'timestamp' ) ) . equal ( null ) ;
235+ break ;
236+ case 1 :
237+ should ( snapshot . get ( 'timestamp' ) ) . be . an . instanceOf ( firebase . firestore . Timestamp ) ;
238+ break ;
239+ case 2 :
240+ should ( snapshot . get ( 'timestamp' ) ) . be . an . instanceOf ( firebase . firestore . Timestamp ) ;
241+ should ( snapshot . get ( 'timestamp' ) . isEqual ( previous . get ( 'timestamp' ) ) ) . equal ( true ) ;
242+ break ;
243+ case 3 :
244+ should ( snapshot . get ( 'timestamp' ) ) . be . an . instanceOf ( firebase . firestore . Timestamp ) ;
245+ should ( snapshot . get ( 'timestamp' ) . isEqual ( previous . get ( 'timestamp' ) ) ) . equal ( false ) ;
246+ subscription ( ) ;
247+ resolve ( ) ;
248+ break ;
249+ }
250+ } catch ( e ) {
251+ reject ( e ) ;
243252 }
244253 previous = snapshot ;
245254 } , reject ) ;
@@ -253,13 +262,29 @@ describe('firestore()', function () {
253262 } ) ;
254263 it ( "handles 'none'" , async function ( ) {
255264 firebase . firestore ( ) . settings ( { serverTimestampBehavior : 'none' } ) ;
256- const ref = firebase . firestore ( ) . doc ( `${ COLLECTION } /getData ` ) ;
265+ const ref = firebase . firestore ( ) . doc ( `${ COLLECTION } /serverTimestampNone ` ) ;
257266
258267 const promise = new Promise ( ( resolve , reject ) => {
268+ let counter = 0 ;
259269 const subscription = ref . onSnapshot ( snapshot => {
260- should ( snapshot . get ( 'timestamp' ) ) . equal ( null ) ;
261- subscription ( ) ;
262- resolve ( ) ;
270+ try {
271+ switch ( counter ++ ) {
272+ case 0 :
273+ // The initial callback snapshot should have no value for the timestamp, it has not been set at all
274+ should ( snapshot . get ( 'timestamp' ) ) . equal ( null ) ;
275+ break ;
276+ case 1 :
277+ should ( snapshot . get ( 'timestamp' ) ) . be . an . instanceOf ( firebase . firestore . Timestamp ) ;
278+ subscription ( ) ;
279+ resolve ( ) ;
280+ break ;
281+ default :
282+ // there should only be initial callback and set callback, any other callbacks are a fail
283+ reject ( new Error ( 'too many callbacks' ) ) ;
284+ }
285+ } catch ( e ) {
286+ reject ( e ) ;
287+ }
263288 } , reject ) ;
264289 } ) ;
265290
0 commit comments