Skip to content

Commit 9b1873e

Browse files
committed
fix(firestore): do not return idField on valueChanges if document does not exists
1 parent a26676c commit 9b1873e

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

src/firestore/document/document.spec.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ describe('AngularFirestoreDocument', () => {
3636

3737
it('should get unwrapped snapshot', async (done: any) => {
3838
const randomCollectionName = afs.firestore.collection('a').doc().id;
39-
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`) as firebase.firestore.DocumentReference<Stock>;
40-
const stock = new AngularFirestoreDocument(ref, afs);
39+
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`) as DocumentReference<Stock>;
40+
const stock = new AngularFirestoreDocument<Stock>(ref, afs);
4141
await stock.set(FAKE_STOCK_DATA);
4242
const obs$ = stock.valueChanges();
4343
obs$.pipe(take(1)).subscribe(async data => {
@@ -46,10 +46,9 @@ describe('AngularFirestoreDocument', () => {
4646
});
4747
});
4848

49-
/* TODO(jamesdaniels): test is flaking, look into this
5049
it('should optionally map the doc ID to the emitted data object', async (done: any) => {
5150
const randomCollectionName = afs.firestore.collection('a').doc().id;
52-
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`);
51+
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`) as DocumentReference<Stock>;
5352
const stock = new AngularFirestoreDocument<Stock>(ref, afs);
5453
await stock.set(FAKE_STOCK_DATA);
5554
const idField = 'myCustomID';
@@ -59,7 +58,7 @@ describe('AngularFirestoreDocument', () => {
5958
expect(data).toEqual(jasmine.objectContaining(FAKE_STOCK_DATA));
6059
stock.delete().then(done).catch(done.fail);
6160
});
62-
});*/
61+
});
6362

6463
});
6564

@@ -81,18 +80,6 @@ describe('AngularFirestoreDocument', () => {
8180
});
8281
});
8382

84-
it('should get unwrapped snapshot', async (done: any) => {
85-
const randomCollectionName = afs.firestore.collection('a').doc().id;
86-
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`) as DocumentReference<Stock>;
87-
const stock = new AngularFirestoreDocument<Stock>(ref, afs);
88-
await stock.set(FAKE_STOCK_DATA);
89-
const obs$ = stock.valueChanges();
90-
obs$.pipe(take(1)).subscribe(async data => {
91-
expect(data).toEqual(FAKE_STOCK_DATA);
92-
stock.delete().then(done).catch(done.fail);
93-
});
94-
});
95-
9683
});
9784

9885
});

src/firestore/document/document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class AngularFirestoreDocument<T = DocumentData> {
8888
valueChanges<K extends string>(options: { idField?: K } = {}): Observable<T | undefined> {
8989
return this.snapshotChanges().pipe(
9090
map(({ payload }) =>
91-
options.idField ? {
91+
options.idField && payload.exists ? {
9292
...payload.data(),
9393
...{ [options.idField]: payload.id }
9494
} as T & { [T in K]: string } : payload.data()

0 commit comments

Comments
 (0)