Closed cjoecker closed 3 months ago
It sounds like you might need to inline the dependency to get this to work like that. (reference). Have you tried that?
@airjp73 good point! But after adding the inline dependency configuration, it is still not working. I open an issue in vitest to see if it is coming from the library.
also running into this issue, any luck @cjoecker ? I also looked into rendering validated form in a remix stub (an experimental testing utility for remix seen used here https://github.com/remix-run/remix/blob/dev/packages/remix-testing/__tests__/stub-test.tsx) but that also didn't work unfortunately
@madmax141 nope. Also still no answer in the Vitest
issue :(
Looks like we are seeing this newly in our E2E tests after updating to Remix v2 and remix-validated-forms 5.1.3
Seems to be fixed in 5.1.4 :)
It seems this error is happening in actual apps too, not just in vitest. It's looking like it's a dependency resolution problem where RVF is pulling in a different version of remix from the rest of the app.
This should be fixed now in 5.1.5.
@airjp73 I updated all dependencies in the codesandbox but I still get the same error ðŸ˜
I got this answer from the vitest
maintainer but I still didn't manage to make it work. Feel free to give it a try.
As a workaround for the people still struggling with this, I'm using now the createRemixStub for mocking the useLoaderData
and it is working fine.
Which packages are impacted?
remix-validated-form
@remix-validated-form/with-zod
@remix-validated-form/with-yup
zod-form-data
What version of these packages are you using?
remox-validated-form
: 5.0.2Please provide a link to a minimal reproduction of the issue.
https://codesandbox.io/p/sandbox/react-typescript-forked-vzq65s?file=%2Fsrc%2FApp.test.tsx%3A14%2C24
Steps to Reproduce the Bug or Issue
vitest
andtesting-library
ValidatedForm
to a component and render it in a testuseActionData
Expected behavior
useActionData
is moked and the erroruseActionData must be used within a data router
is not shownAdditional context
I know that
useActionData
is mocked because in themockImplementation
I'm logging something that is shown in the console of the test because I also use the hook in theDemo
component. ButValidatedForm
is not using the mock and I still don't know why.