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
4 changes: 2 additions & 2 deletions packages/firestore/src/lite-api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export function collection<AppModelType, DbModelType extends DocumentData>(
throw new FirestoreError(
Code.INVALID_ARGUMENT,
'Expected first argument to collection() to be a CollectionReference, ' +
'a DocumentReference or FirebaseFirestore'
'a DocumentReference or Firestore'
Comment on lines 516 to +517
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While updating this error message, it would be a good opportunity to add a test case to packages/firestore/test/lite/integration.test.ts that validates this specific error for the collection() function. This would improve test coverage and ensure this error message is validated, similar to the existing test for doc().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I’ve updated the existing doc() test to expect
Firestore and added a corresponding test for collection() to improve
coverage. Please let me know if this looks good.

);
}
const absolutePath = parent._path.child(
Expand Down Expand Up @@ -652,7 +652,7 @@ export function doc<AppModelType, DbModelType extends DocumentData>(
throw new FirestoreError(
Code.INVALID_ARGUMENT,
'Expected first argument to doc() to be a CollectionReference, ' +
'a DocumentReference or FirebaseFirestore'
'a DocumentReference or Firestore'
Comment on lines 654 to +655
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This error message change is correct. However, it looks like the corresponding unit test in packages/firestore/test/lite/integration.test.ts (around line 292) that validates this error message has not been updated. This will cause the test to fail. Please update the test to expect 'Firestore' instead of 'FirebaseFirestore'.

);
}
const absolutePath = parent._path.child(
Expand Down
26 changes: 25 additions & 1 deletion packages/firestore/test/lite/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ describe('doc', () => {
// @ts-expect-error
doc({}, 'coll/doc')
).to.throw(
'Expected first argument to doc() to be a CollectionReference, a DocumentReference or FirebaseFirestore'
'Expected first argument to doc() to be a CollectionReference, a DocumentReference or Firestore'
);
expect(() => doc(db, 'coll')).to.throw(
'Invalid document reference. Document references must have an even ' +
Expand All @@ -307,6 +307,30 @@ describe('doc', () => {
);
});
});
it('validates collection path', () => {
return withTestDb(db => {
expect(() =>
// @ts-expect-error
collection({}, 'coll')
).to.throw(
'Expected first argument to collection() to be a CollectionReference, a DocumentReference or Firestore'
);

expect(() => collection(db, '')).to.throw(
'Function collection() cannot be called with an empty path.'
);

expect(() => collection(db, 'coll/doc')).to.throw(
'Invalid collection reference. Collection references must have an odd ' +
'number of segments, but coll/doc has 2.'
);

expect(() => collection(db, 'coll//doc')).to.throw(
'Invalid segment (coll//doc). Paths must not contain // in them.'
);
});
});


it('supports AutoId', () => {
return withTestDb(db => {
Expand Down
Loading