Skip to content

Commit 19990fc

Browse files
committed
itest for Snapshot created by a DocSnap bundle
1 parent f88748f commit 19990fc

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/firestore/test/integration/api/database.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ import { DEFAULT_SETTINGS, DEFAULT_PROJECT_ID } from '../util/settings';
8686

8787
use(chaiAsPromised);
8888

89+
const SNAPSHOT_TEST_TIMEOUT = 5000;
90+
8991
apiDescribe('Database', persistence => {
9092
it('can set a document', () => {
9193
return withTestDoc(persistence, docRef => {
@@ -1184,6 +1186,41 @@ apiDescribe('Database', persistence => {
11841186
});
11851187
});
11861188

1189+
it('DocumentSnapshot events for snapshot created by a bundle', function (done) {
1190+
this.timeout(SNAPSHOT_TEST_TIMEOUT);
1191+
withTestDoc(persistence, async (docRef, db) => {
1192+
const secondUpdateFound = new Deferred();
1193+
let count = 0;
1194+
await setDoc(docRef, { a: 0 });
1195+
await waitForPendingWrites(db);
1196+
const docSnap = await getDoc(docRef);
1197+
expect(docSnap.data()).to.deep.equal({ a: 0 });
1198+
const unlisten = onSnapshot(
1199+
db,
1200+
docSnap.toJSON(),
1201+
(doc: DocumentSnapshot) => {
1202+
if (doc) {
1203+
count++;
1204+
if (count === 1) {
1205+
expect(doc.data()).to.deep.equal({ a: 1 });
1206+
} else {
1207+
expect(doc.data()).to.deep.equal({ b: 1 });
1208+
secondUpdateFound.resolve();
1209+
}
1210+
}
1211+
}
1212+
);
1213+
await setDoc(docRef, { a: 1 }).then(() => {
1214+
setDoc(docRef, { b: 1 });
1215+
});
1216+
await secondUpdateFound.promise;
1217+
console.error('DEDB done!');
1218+
expect(count).to.equal(2);
1219+
unlisten();
1220+
done();
1221+
});
1222+
});
1223+
11871224
it('Listen can be called multiple times', () => {
11881225
return withTestCollection(persistence, {}, coll => {
11891226
const docA = doc(coll);

0 commit comments

Comments
 (0)