fix(tests): fix all failing tests#837
Open
BrendanC23 wants to merge 1 commit intoreact-hook-form:masterfrom
Open
fix(tests): fix all failing tests#837BrendanC23 wants to merge 1 commit intoreact-hook-form:masterfrom
BrendanC23 wants to merge 1 commit intoreact-hook-form:masterfrom
Conversation
1. Remove `/\\.` from `vitest.config.ts`. This was necessary to fix the error `No test files found`. This can also be fixed by updating Vitest to version 4, but this has a change to how snapshots are stored. See [the migration guide](https://vitest.dev/guide/migration.html#changes-to-mocking). All of the tests are found by removing `/\\.`, so the Vitest upgrade is better in a later PR. 1. Inlined `z` in `vitest.config.ts` to spy on `parse()` from `zod/v4/core`. Without this, a `TypeError: Cannot redefine property: parse` error occurs. 1. Change `bun test` to `bun run test` in CONTRIBUTING.md. `bun test` runs Bun's native test runner, not the `test` script. 1. Add `Test` stage to `.github/workflows/main.yml`. It was removed in [this PR](react-hook-form#699) and the tests haven't been running in CI. 1. Fix failing tests Notes: 1. All * Fixed tests that called `useForm` outside of a component. This fixed the errors `Error: Invalid hook call. Hooks can only be called inside of the body of a function component.` and `TypeError: Cannot read properties of null (reading 'useRef')`. 1. Arktype * [This PR](react-hook-form#753) changed from directly calling Arktype to using standard schema. Part of this transition was changing `type: error.code` to `type: ''` (because `error.code` is not part of the standard schema). This required an update to the snapshot. 1. Superstruct * Fix validation of schemas that perform coercion (`{ coerce: true }` must be passed in) * Added additional overload for type definition `superstructResolver` that improves handling of coerced schemas (This fixes a type error with the form values). * Fix definition of coercion schema so that it correctly converts from number to string * As mentioned in [this issue](ianstormtaylor/superstruct#1159), there is no way to infer the input type of a coerced schema. A [separate PR](ianstormtaylor/superstruct#1181) would be necessary. Some of the type inference tests have been changed to manually provide the input type (this enables `watch` to return the correct value for a coerced schema). 1. Typeschema * The `for` loop was looping through the `schemaErrors` variable, but the current error was based on the `typeschemaErrors[0]` variable. This caused only the first error to be returned. * Change from spying on `typeschema.validate` to watching `schema["~standard"]` 1. Zod * Fixed Zod tests that spied on `schema.parse()` instead of `z4.parse()` * Added missing snapshots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/\\.fromvitest.config.ts. This was necessary to fix the errorNo test files found. This can also be fixed by updating Vitest to version 4, but this has a change to how snapshots are stored. See the migration guide. All of the tests are found by removing/\\., so the Vitest upgrade is better in a later PR.zinvitest.config.tsto spy onparse()fromzod/v4/core. Without this, aTypeError: Cannot redefine property: parseerror occurs.bun testtobun run testin CONTRIBUTING.md.bun testruns Bun's native test runner, not thetestscript.Teststage to.github/workflows/main.yml. It was removed in this PR and the tests haven't been running in CI.Notes:
useFormoutside of a component. This fixed the errorsError: Invalid hook call. Hooks can only be called inside of the body of a function component.andTypeError: Cannot read properties of null (reading 'useRef').type: error.codetotype: ''(becauseerror.codeis not part of the standard schema). This required an update to the snapshot.{ coerce: true }must be passed in)superstructResolverthat improves handling of coerced schemas (This fixes a type error with the form values).watchto return the correct value for a coerced schema).forloop was looping through theschemaErrorsvariable, but the current error was based on thetypeschemaErrors[0]variable. This caused only the first error to be returned.typeschema.validateto watchingschema["~standard"]schema.parse()instead ofz4.parse()Fixes #832