Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-sheep-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/firestore': patch
---

Fix: Corrected misleading error message when doc() is called with undefined.
2 changes: 1 addition & 1 deletion packages/firestore/src/lite-api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export function doc<AppModelType, DbModelType extends DocumentData>(
) {
throw new FirestoreError(
Code.INVALID_ARGUMENT,
'Expected first argument to collection() to be a CollectionReference, ' +
'Expected first argument to doc() to be a CollectionReference, ' +
'a DocumentReference or FirebaseFirestore'
);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/firestore/test/lite/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ describe('doc', () => {

it('validates path', () => {
return withTestDb(db => {
expect(() =>
// @ts-expect-error
doc({}, 'coll/doc')
).to.throw(
'Expected first argument to doc() to be a CollectionReference, a DocumentReference or FirebaseFirestore'
);
expect(() => doc(db, 'coll')).to.throw(
'Invalid document reference. Document references must have an even ' +
'number of segments, but coll has 1.'
Expand Down
Loading