Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion packages/firestore/src/lite-api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,12 @@ export function doc<AppModelType, DbModelType extends DocumentData>(
path?: string,
...pathSegments: string[]
): DocumentReference<AppModelType, DbModelType> {
if (parent === undefined) {
throw new FirestoreError(
Code.INVALID_ARGUMENT,
'Function doc() cannot be called with an undefined first argument.'
);
}
parent = getModularInstance(parent);

// We allow omission of 'pathString' but explicitly prohibit passing in both
Expand All @@ -651,7 +657,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 @@

it('validates path', () => {
return withTestDb(db => {
expect(() => doc(undefined as any, 'coll/doc')).to.throw(

Check failure on line 288 in packages/firestore/test/lite/integration.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
'Function doc() cannot be called with an empty first argument.'
);
expect(() => doc({} as any, 'coll/doc')).to.throw(

Check failure on line 291 in packages/firestore/test/lite/integration.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
'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