@@ -1186,15 +1186,84 @@ apiDescribe('Database', persistence => {
11861186 } ) ;
11871187 } ) ;
11881188
1189+ it ( 'Listen can be called multiple times' , ( ) => {
1190+ return withTestCollection ( persistence , { } , coll => {
1191+ const docA = doc ( coll ) ;
1192+ const deferred1 = new Deferred < void > ( ) ;
1193+ const deferred2 = new Deferred < void > ( ) ;
1194+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
1195+ setDoc ( docA , { foo : 'bar' } ) . then ( ( ) => {
1196+ onSnapshot ( docA , ( ) => {
1197+ deferred1 . resolve ( ) ;
1198+ onSnapshot ( docA , ( ) => deferred2 . resolve ( ) ) ;
1199+ } ) ;
1200+ } ) ;
1201+ return Promise . all ( [ deferred1 . promise , deferred2 . promise ] ) . then ( ( ) => { } ) ;
1202+ } ) ;
1203+ } ) ;
1204+
11891205 it ( 'DocumentSnapshot events for snapshot created by a bundle' , function ( done ) {
11901206 this . timeout ( SNAPSHOT_TEST_TIMEOUT ) ;
1191- withTestDoc ( persistence , async ( docRef , db ) => {
1207+ void withTestDoc ( persistence , async ( docRef , db ) => {
1208+ const updateFound = new Deferred ( ) ;
1209+ await setDoc ( docRef , { a : 0 } ) ;
1210+ await waitForPendingWrites ( db ) ;
1211+ const docSnap = await getDoc ( docRef ) ;
1212+ expect ( docSnap . data ( ) ) . to . deep . equal ( { a : 0 } ) ;
1213+ const unlisten = onSnapshot (
1214+ db ,
1215+ docSnap . toJSON ( ) ,
1216+ ( doc : DocumentSnapshot ) => {
1217+ if ( doc ) {
1218+ expect ( doc . data ( ) ) . to . deep . equal ( { a : 0 } ) ;
1219+ updateFound . resolve ( ) ;
1220+ }
1221+ }
1222+ ) ;
1223+ await updateFound . promise ;
1224+ unlisten ( ) ;
1225+ done ( ) ;
1226+ } ) ;
1227+ } ) ;
1228+ it ( 'DocumentSnapshot updated doc events in snapshot created by a bundle' , function ( done ) {
1229+ this . timeout ( SNAPSHOT_TEST_TIMEOUT ) ;
1230+ void withTestDoc ( persistence , async ( docRef , db ) => {
11921231 const secondUpdateFound = new Deferred ( ) ;
1232+ await setDoc ( docRef , { a : 0 } ) ;
1233+ await waitForPendingWrites ( db ) ;
1234+ const docSnap = await getDoc ( docRef ) ;
1235+ expect ( docSnap . data ( ) ) . to . deep . equal ( { a : 0 } ) ;
11931236 let count = 0 ;
1237+ const unlisten = onSnapshot (
1238+ db ,
1239+ docSnap . toJSON ( ) ,
1240+ ( doc : DocumentSnapshot ) => {
1241+ if ( doc ) {
1242+ count ++ ;
1243+ if ( count === 1 ) {
1244+ expect ( doc . data ( ) ) . to . deep . equal ( { a : 1 } ) ;
1245+ secondUpdateFound . resolve ( ) ;
1246+ }
1247+ }
1248+ }
1249+ ) ;
1250+ await setDoc ( docRef , { a : 1 } ) ;
1251+ await secondUpdateFound . promise ;
1252+ expect ( count ) . to . equal ( 1 ) ;
1253+ unlisten ( ) ;
1254+ done ( ) ;
1255+ } ) ;
1256+ } ) ;
1257+
1258+ it ( 'DocumentSnapshot multiple events for snapshot created by a bundle' , function ( done ) {
1259+ this . timeout ( SNAPSHOT_TEST_TIMEOUT ) ;
1260+ void withTestDoc ( persistence , async ( docRef , db ) => {
1261+ const secondUpdateFound = new Deferred ( ) ;
11941262 await setDoc ( docRef , { a : 0 } ) ;
11951263 await waitForPendingWrites ( db ) ;
11961264 const docSnap = await getDoc ( docRef ) ;
11971265 expect ( docSnap . data ( ) ) . to . deep . equal ( { a : 0 } ) ;
1266+ let count = 0 ;
11981267 const unlisten = onSnapshot (
11991268 db ,
12001269 docSnap . toJSON ( ) ,
@@ -1211,32 +1280,15 @@ apiDescribe('Database', persistence => {
12111280 }
12121281 ) ;
12131282 await setDoc ( docRef , { a : 1 } ) . then ( ( ) => {
1214- setDoc ( docRef , { b : 1 } ) ;
1283+ void setDoc ( docRef , { b : 1 } ) ;
12151284 } ) ;
12161285 await secondUpdateFound . promise ;
1217- console . error ( 'DEDB done!' ) ;
12181286 expect ( count ) . to . equal ( 2 ) ;
12191287 unlisten ( ) ;
12201288 done ( ) ;
12211289 } ) ;
12221290 } ) ;
12231291
1224- it ( 'Listen can be called multiple times' , ( ) => {
1225- return withTestCollection ( persistence , { } , coll => {
1226- const docA = doc ( coll ) ;
1227- const deferred1 = new Deferred < void > ( ) ;
1228- const deferred2 = new Deferred < void > ( ) ;
1229- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1230- setDoc ( docA , { foo : 'bar' } ) . then ( ( ) => {
1231- onSnapshot ( docA , ( ) => {
1232- deferred1 . resolve ( ) ;
1233- onSnapshot ( docA , ( ) => deferred2 . resolve ( ) ) ;
1234- } ) ;
1235- } ) ;
1236- return Promise . all ( [ deferred1 . promise , deferred2 . promise ] ) . then ( ( ) => { } ) ;
1237- } ) ;
1238- } ) ;
1239-
12401292 it ( 'Metadata only changes are not fired when no options provided' , ( ) => {
12411293 return withTestDoc ( persistence , docRef => {
12421294 const secondUpdateFound = new Deferred ( ) ;
0 commit comments