@@ -840,15 +840,15 @@ apiDescribe('Database', persistence => {
840
840
const gotInitialSnapshot = new Deferred < void > ( ) ;
841
841
const docA = doc ( coll , 'a' ) ;
842
842
843
- const unsubscribe1 = onSnapshot ( docA , snap => {
843
+ onSnapshot ( docA , snap => {
844
844
events . push ( 'doc' ) ;
845
845
gotInitialSnapshot . resolve ( ) ;
846
846
} ) ;
847
847
await gotInitialSnapshot . promise ;
848
848
events = [ ] ;
849
849
850
850
const done = new Deferred < void > ( ) ;
851
- const unsubscribe2 = onSnapshotsInSync ( db , ( ) => {
851
+ onSnapshotsInSync ( db , ( ) => {
852
852
events . push ( 'snapshots-in-sync' ) ;
853
853
if ( events . length === 3 ) {
854
854
// We should have an initial snapshots-in-sync event, then a snapshot
@@ -865,8 +865,6 @@ apiDescribe('Database', persistence => {
865
865
866
866
await setDoc ( docA , { foo : 3 } ) ;
867
867
await done . promise ;
868
- unsubscribe1 ( ) ;
869
- unsubscribe2 ( ) ;
870
868
} ) ;
871
869
} ) ;
872
870
@@ -1087,29 +1085,24 @@ apiDescribe('Database', persistence => {
1087
1085
} ) ;
1088
1086
1089
1087
it ( 'DocumentSnapshot events for nonexistent document' , ( ) => {
1090
- return withTestCollection ( persistence , { } , async col => {
1088
+ return withTestCollection ( persistence , { } , col => {
1091
1089
const docA = doc ( col ) ;
1092
1090
const storeEvent = new EventsAccumulator < DocumentSnapshot > ( ) ;
1093
- const unsubscribe = onSnapshot ( docA , storeEvent . storeEvent ) ;
1094
- await storeEvent . awaitEvent ( ) . then ( snap => {
1091
+ onSnapshot ( docA , storeEvent . storeEvent ) ;
1092
+ return storeEvent . awaitEvent ( ) . then ( snap => {
1095
1093
expect ( snap . exists ( ) ) . to . be . false ;
1096
1094
expect ( snap . data ( ) ) . to . equal ( undefined ) ;
1095
+ return storeEvent . assertNoAdditionalEvents ( ) ;
1097
1096
} ) ;
1098
- await storeEvent . assertNoAdditionalEvents ( ) ;
1099
- unsubscribe ( ) ;
1100
1097
} ) ;
1101
1098
} ) ;
1102
1099
1103
1100
it ( 'DocumentSnapshot events for add data to document' , ( ) => {
1104
- return withTestCollection ( persistence , { } , async col => {
1101
+ return withTestCollection ( persistence , { } , col => {
1105
1102
const docA = doc ( col ) ;
1106
1103
const storeEvent = new EventsAccumulator < DocumentSnapshot > ( ) ;
1107
- const unsubscribe = onSnapshot (
1108
- docA ,
1109
- { includeMetadataChanges : true } ,
1110
- storeEvent . storeEvent
1111
- ) ;
1112
- await storeEvent
1104
+ onSnapshot ( docA , { includeMetadataChanges : true } , storeEvent . storeEvent ) ;
1105
+ return storeEvent
1113
1106
. awaitEvent ( )
1114
1107
. then ( snap => {
1115
1108
expect ( snap . exists ( ) ) . to . be . false ;
@@ -1131,7 +1124,6 @@ apiDescribe('Database', persistence => {
1131
1124
// TODO(b/295872012): Figure out a way to check for all scenarios.
1132
1125
// expect(snap.metadata.hasPendingWrites).to.be.false;
1133
1126
} ) ;
1134
- unsubscribe ( ) ;
1135
1127
} ) ;
1136
1128
} ) ;
1137
1129
0 commit comments