docs(form-core): update validateAllFields description#2117
docs(form-core): update validateAllFields description#2117harry-whorlow merged 1 commit intomainfrom
Conversation
📝 WalkthroughWalkthroughUpdated Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit b0b50c7
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version Preview2 package(s) bumped directly, 11 bumped as dependents. 🟨 Minor bumps
🟩 Patch bumps
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/form-core/tests/FormApi.spec.ts (1)
2020-2064: Field-level “all fields” tests currently validate only one mounted field.The test titles say “all fields,” but only
firstNameis mounted/asserted in both cases. Consider mountinglastNametoo (or rename tests) so iteration regressions are caught.♻️ Suggested test hardening
it('should validate all fields consistently - field level onChange validators', async () => { const form = new FormApi({ defaultValues: { firstName: '', lastName: '', }, }) - const field = new FieldApi({ + const firstNameField = new FieldApi({ form, name: 'firstName', validators: { onChange: ({ value }) => (value.length > 0 ? undefined : 'is required'), }, }) + const lastNameField = new FieldApi({ + form, + name: 'lastName', + validators: { + onChange: ({ value }) => (value.length > 0 ? undefined : 'is required'), + }, + }) form.mount() - field.mount() + firstNameField.mount() + lastNameField.mount() await form.validateAllFields('change') - expect(field.getMeta().errorMap.onChange).toEqual('is required') + expect(firstNameField.getMeta().errorMap.onChange).toEqual('is required') + expect(lastNameField.getMeta().errorMap.onChange).toEqual('is required') }) it('should validate all fields consistently - field level onSubmit validators', async () => { const form = new FormApi({ defaultValues: { firstName: '', lastName: '', }, }) - const field = new FieldApi({ + const firstNameField = new FieldApi({ form, name: 'firstName', validators: { onSubmit: ({ value }) => (value.length > 0 ? undefined : 'is required'), }, }) + const lastNameField = new FieldApi({ + form, + name: 'lastName', + validators: { + onSubmit: ({ value }) => (value.length > 0 ? undefined : 'is required'), + }, + }) form.mount() - field.mount() + firstNameField.mount() + lastNameField.mount() await form.validateAllFields('submit') - expect(field.getMeta().errorMap.onSubmit).toEqual('is required') + expect(firstNameField.getMeta().errorMap.onSubmit).toEqual('is required') + expect(lastNameField.getMeta().errorMap.onSubmit).toEqual('is required') })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/form-core/tests/FormApi.spec.ts` around lines 2020 - 2064, The tests for validateAllFields currently only mount and assert the 'firstName' FieldApi, so add a second FieldApi for 'lastName' (using FieldApi with form, name: 'lastName', and the same validators) and call mount() on it before await form.validateAllFields('change'|'submit'), then assert that lastName.getMeta().errorMap.onChange (or .onSubmit) equals 'is required'; alternatively, rename the test titles if you intentionally only want to exercise a single field. Ensure references to FormApi, FieldApi, validateAllFields, mount, and getMeta are used to locate and update the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/form-core/tests/FormApi.spec.ts`:
- Around line 2020-2064: The tests for validateAllFields currently only mount
and assert the 'firstName' FieldApi, so add a second FieldApi for 'lastName'
(using FieldApi with form, name: 'lastName', and the same validators) and call
mount() on it before await form.validateAllFields('change'|'submit'), then
assert that lastName.getMeta().errorMap.onChange (or .onSubmit) equals 'is
required'; alternatively, rename the test titles if you intentionally only want
to exercise a single field. Ensure references to FormApi, FieldApi,
validateAllFields, mount, and getMeta are used to locate and update the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1283b8d5-7804-432a-987a-8afc2f7e84d2
📒 Files selected for processing (2)
packages/form-core/src/FormApi.tspackages/form-core/tests/FormApi.spec.ts
|
relates to #1208 |
09fff77 to
b0b50c7
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/form-core/tests/FormApi.spec.ts (1)
1971-1992: Add a regression guard that form-level validators are not invoked here.These tests currently verify field-level errors only. A small negative assertion would lock the intended
validateAllFieldscontract more tightly.Suggested test hardening
it('should validate all fields consistently - field level onSubmit validators', async () => { + const formOnSubmit = vi.fn().mockReturnValue('form-level error') const form = new FormApi({ defaultValues: { firstName: '', lastName: '', }, + validators: { + onSubmit: formOnSubmit, + }, }) const field = new FieldApi({ form, name: 'firstName', validators: { onSubmit: ({ value }) => (value.length > 0 ? undefined : 'is required'), }, }) form.mount() field.mount() await form.validateAllFields('submit') expect(field.getMeta().errorMap.onSubmit).toEqual('is required') + expect(formOnSubmit).not.toHaveBeenCalled() })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/form-core/tests/FormApi.spec.ts` around lines 1971 - 1992, Add a negative assertion to ensure form-level validators are not invoked in this test: after calling form.validateAllFields('submit') and asserting the field error, assert that form-level validator state (e.g., any form.getMeta().errorMap.onSubmit or a mock form-level validator call counter) remains undefined/unchanged so the test guarantees only FieldApi.onSubmit ran; locate FormApi, FieldApi, and validateAllFields in the test to add this check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/form-core/tests/FormApi.spec.ts`:
- Around line 1971-1992: Add a negative assertion to ensure form-level
validators are not invoked in this test: after calling
form.validateAllFields('submit') and asserting the field error, assert that
form-level validator state (e.g., any form.getMeta().errorMap.onSubmit or a mock
form-level validator call counter) remains undefined/unchanged so the test
guarantees only FieldApi.onSubmit ran; locate FormApi, FieldApi, and
validateAllFields in the test to add this check.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 81096b9d-0b5c-42dd-898d-7131765763e1
📒 Files selected for processing (2)
packages/form-core/src/FormApi.tspackages/form-core/tests/FormApi.spec.ts
✅ Files skipped from review due to trivial changes (1)
- packages/form-core/src/FormApi.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2117 +/- ##
==========================================
- Coverage 90.35% 90.25% -0.10%
==========================================
Files 38 49 +11
Lines 1752 2043 +291
Branches 444 532 +88
==========================================
+ Hits 1583 1844 +261
- Misses 149 179 +30
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary by CodeRabbit
Tests
Chores