diff --git a/.changeset/thin-sheep-smoke.md b/.changeset/thin-sheep-smoke.md new file mode 100644 index 00000000000..83af71b0d0a --- /dev/null +++ b/.changeset/thin-sheep-smoke.md @@ -0,0 +1,5 @@ +--- +'@firebase/firestore': patch +--- + +Fix: Corrected misleading error message when doc() is called with undefined. diff --git a/packages/firestore/src/lite-api/reference.ts b/packages/firestore/src/lite-api/reference.ts index f38dad9a078..e6c5fd7b056 100644 --- a/packages/firestore/src/lite-api/reference.ts +++ b/packages/firestore/src/lite-api/reference.ts @@ -651,7 +651,7 @@ export function doc( ) { 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' ); } diff --git a/packages/firestore/test/lite/integration.test.ts b/packages/firestore/test/lite/integration.test.ts index 7fb7eafcb1e..54595ade4d4 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -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.'