Comments (5)
useFormStatus
is not available in [email protected]
(the version in your package.json). It's available in React Canary/Beta/Experimental chanels. To solve it you can:
npm i react@canary react-dom@canary
- wait until react@19 is released as stable
- mock
useFormStatus
until the release.
Note
Next.js doesn't use the react version in your package.json, it uses a pre-compiled canary version. Updating react (or even removing it) will only affect tests.
from next.js.
I get these same types of errors when my tests touch code that contains React.cache
. This is included in the internal React version Next is using, but not in the 18.2 release of React itself. It seems like the module resolution that is used by vitest
(and presumably jest) isn't the same as whatever Next is doing.
Edit: created an issue for my case of this: #64783
from next.js.
Was this ever resolved ? Got a similar error Error: Uncaught [TypeError: (0 , _reactdom.useFormStatus) is not a function]
in a simple jest test.
When I remove uses of useFormStatus
in source files, the tests pass.
from next.js.
Thanks. Successfully implemented the first and third option. For the third, which is what I will be using for projects I am currently working:
import { render, screen } from '@testing-library/react';
import Button from './button';
import { useFormStatus } from 'react-dom';
jest.mock('react-dom', () => ({
useFormStatus: jest.fn(),
}));
describe('Button', () => {
it('should render label', () => {
// Arrange
const label = 'Button';
(useFormStatus as jest.Mock).mockResolvedValue(true);
render(<Button type="button" label={label} />);
// Act and Assertions ...
});
});
from next.js.
Just to set expectations, the code I posted last night mocking useFormStatus just prevents the error. The test I was originally working on when posting this issue doesn't care about useFormStatus or its parameter values. Later I did try a test where I destructured the mock to set the pending parameter to be true. I could not get this to work. Stepping through the code pending always shows undefined.
// Arrange
const label = 'Button';
(useFormStatus as jest.Mock).mockResolvedValue({ pending: true });
render(
<form action=""> //
<Button
type="button"
label={label}
/>
</form>
);
Have to move along to other priorities, but if I do find a way to make this usable in a test will post here.
from next.js.
Related Issues (20)
- NextNodeServer handleNextImageRequest doens't work as expected with assetPrefix and custom next/image loader
- Returning a string from a page component causes hydration mismatch error HOT 5
- Opentelemetry - Spans for static resources and API pages not part of page load trace
- Enabling `experimental.reactCompiler` causes hydration error when using styled-jsx
- Module not found: Can't resolve '@node-rs/argon2-wasm32-wasi' HOT 2
- __turbopack_resolve_absolute_path__ is not a function HOT 1
- window.history.pushState does not work with transitions HOT 2
- ES Modules may not assign module.exports or exports.*, Use ESM export syntax HOT 1
- Parallel Route Modal closed using router.push cannot open again until hard refresh HOT 2
- "res.status(200).json() is not a function" is this a bug? HOT 3
- next JS 13.0.6 HOT 2
- Component Reinitialization Issue with `loading.tsx` and `revalidateTag` HOT 1
- CSS module of client component is injected to DOM before global css in layout regardless of import order HOT 1
- Docs: Pages and layouts section not opening (again) HOT 2
- MSW Turbopack fails to import HOT 6
- ReferenceError: window is not defined... in client component? HOT 7
- Next 14 is not working properly in docker on windows with bun, but normal at local terminal HOT 6
- Sourcemaps are not loaded in index pages with a dynamic route level deeper than one
- SVG with icons not updating after change HOT 6
- [backport request] Backport fix of an already-fixed bug of next-swc HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.