The warning/error is caused by updates to the MarketCardVoidByTimeRange component's state during test execution not being wrapped in a proper act function. React needs these act wrappers to emulate the correct synchronous behavior of browser updates so that you can test the UI behavior as it would appear in the browser.
In your case, the relevant portions of your tests are missing an act wrapper, specifically when you call userEvent.type or userEvent.click.
To fix this, wrap the userEvent.type and userEvent.click calls inside the act function:
// expect(
// screen.getByRole(roles.dialog, { name: en.modal.vtr.title }),
// ).toBeInTheDocument();
// });
// });
});
console.error
Warning: An update to MarketCardVoidByTimeRange inside a test was not wrapped in act(...).
code
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
at MarketCardVoidByTimeRange (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/components/manualActions/voidByTimeRange/MarketCardVoidByTimeRange/MarketCardVoidByTimeRange.tsx:37:3)
at QueryClientProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js:65:3)
at QueryClientProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/providers/QueryClientProvider/QueryClientProvider.tsx:16:3)
at FeedbackProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/FeedbackContext/FeedbackContext.tsx:46:3)
at FeedbackWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/FeedbackUtils.tsx:4:3)
at ToastProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/ToastContext/ToastContext.tsx:44:3)
at ToastWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/ToastUtils.tsx:6:3)
at I18nextProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/react-i18next/dist/commonjs/I18nextProvider.js:13:19)
at I18NWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/I18NUtils.tsx:8:3)
at FlagsProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/FlagsContext/FlagsContext.tsx:36:3)
at FeatureFlagsWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/FeatureFlagsUtils.tsx:11:3)
at ThemeContextMock (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/ThemeContext/ThemeContextMock.tsx:10:3)
at PermissionsContextMock (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/PermissionsContext/PermissionsContextMock.tsx:11:8)
at TestWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/TestUtils.tsx:32:3)
at Router (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/react-router/lib/components.tsx:290:13)
at RouterWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/RouterUtils.tsx:10:3)
at printWarning (node_modules/react-dom/cjs/react-dom.development.js:86:30)
at error (node_modules/react-dom/cjs/react-dom.development.js:60:7)
at warnIfUpdatesNotWrappedWithActDEV (node_modules/react-dom/cjs/react-dom.development.js:27589:9)
at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:25508:5)
at dispatchSetState (node_modules/react-dom/cjs/react-dom.development.js:17527:7)
at node_modules/react-hook-form/src/useForm.ts:168:9
at node_modules/react-hook-form/src/useForm.ts:224:9
at node_modules/react-hook-form/src/useForm.ts:395:9
console.error
Warning: An update to MarketCardVoidByTimeRange inside a test was not wrapped in act(...).
code
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
at MarketCardVoidByTimeRange (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/components/manualActions/voidByTimeRange/MarketCardVoidByTimeRange/MarketCardVoidByTimeRange.tsx:37:3)
at QueryClientProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js:65:3)
at QueryClientProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/providers/QueryClientProvider/QueryClientProvider.tsx:16:3)
at FeedbackProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/FeedbackContext/FeedbackContext.tsx:46:3)
at FeedbackWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/FeedbackUtils.tsx:4:3)
at ToastProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/ToastContext/ToastContext.tsx:44:3)
at ToastWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/ToastUtils.tsx:6:3)
at I18nextProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/react-i18next/dist/commonjs/I18nextProvider.js:13:19)
at I18NWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/I18NUtils.tsx:8:3)
at FlagsProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/FlagsContext/FlagsContext.tsx:36:3)
at FeatureFlagsWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/FeatureFlagsUtils.tsx:11:3)
at ThemeContextMock (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/ThemeContext/ThemeContextMock.tsx:10:3)
at PermissionsContextMock (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/PermissionsContext/PermissionsContextMock.tsx:11:8)
at TestWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/TestUtils.tsx:32:3)
at Router (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/react-router/lib/components.tsx:290:13)
at RouterWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/RouterUtils.tsx:10:3)
at printWarning (node_modules/react-dom/cjs/react-dom.development.js:86:30)
at error (node_modules/react-dom/cjs/react-dom.development.js:60:7)
at warnIfUpdatesNotWrappedWithActDEV (node_modules/react-dom/cjs/react-dom.development.js:27589:9)
at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:25508:5)
at dispatchSetState (node_modules/react-dom/cjs/react-dom.development.js:17527:7)
at node_modules/react-hook-form/src/useForm.ts:168:9
at node_modules/react-hook-form/src/useForm.ts:224:9
at node_modules/react-hook-form/src/useForm.ts:395:9
console.error
Warning: An update to MarketCardVoidByTimeRange inside a test was not wrapped in act(...).
code
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
at MarketCardVoidByTimeRange (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/components/manualActions/voidByTimeRange/MarketCardVoidByTimeRange/MarketCardVoidByTimeRange.tsx:37:3)
at QueryClientProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js:65:3)
at QueryClientProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/providers/QueryClientProvider/QueryClientProvider.tsx:16:3)
at FeedbackProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/FeedbackContext/FeedbackContext.tsx:46:3)
at FeedbackWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/FeedbackUtils.tsx:4:3)
at ToastProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/ToastContext/ToastContext.tsx:44:3)
at ToastWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/ToastUtils.tsx:6:3)
at I18nextProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/react-i18next/dist/commonjs/I18nextProvider.js:13:19)
at I18NWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/I18NUtils.tsx:8:3)
at FlagsProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/FlagsContext/FlagsContext.tsx:36:3)
at FeatureFlagsWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/FeatureFlagsUtils.tsx:11:3)
at ThemeContextMock (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/ThemeContext/ThemeContextMock.tsx:10:3)
at PermissionsContextMock (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/PermissionsContext/PermissionsContextMock.tsx:11:8)
at TestWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/TestUtils.tsx:32:3)
at Router (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/react-router/lib/components.tsx:290:13)
at RouterWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/RouterUtils.tsx:10:3)
at printWarning (node_modules/react-dom/cjs/react-dom.development.js:86:30)
at error (node_modules/react-dom/cjs/react-dom.development.js:60:7)
at warnIfUpdatesNotWrappedWithActDEV (node_modules/react-dom/cjs/react-dom.development.js:27589:9)
at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:25508:5)
at dispatchSetState (node_modules/react-dom/cjs/react-dom.development.js:17527:7)
at node_modules/react-hook-form/src/useForm.ts:168:9
at node_modules/react-hook-form/src/useForm.ts:224:9
at node_modules/react-hook-form/src/useForm.ts:395:9
console.error
Warning: An update to MarketCardVoidByTimeRange inside a test was not wrapped in act(...).
code
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
at MarketCardVoidByTimeRange (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/components/manualActions/voidByTimeRange/MarketCardVoidByTimeRange/MarketCardVoidByTimeRange.tsx:37:3)
at QueryClientProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js:65:3)
at QueryClientProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/providers/QueryClientProvider/QueryClientProvider.tsx:16:3)
at FeedbackProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/FeedbackContext/FeedbackContext.tsx:46:3)
at FeedbackWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/FeedbackUtils.tsx:4:3)
at ToastProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/ToastContext/ToastContext.tsx:44:3)
at ToastWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/ToastUtils.tsx:6:3)
at I18nextProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/react-i18next/dist/commonjs/I18nextProvider.js:13:19)
at I18NWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/I18NUtils.tsx:8:3)
at FlagsProvider (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/FlagsContext/FlagsContext.tsx:36:3)
at FeatureFlagsWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/FeatureFlagsUtils.tsx:11:3)
at ThemeContextMock (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/ThemeContext/ThemeContextMock.tsx:10:3)
at PermissionsContextMock (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/contexts/PermissionsContext/PermissionsContextMock.tsx:11:8)
at TestWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/TestUtils.tsx:32:3)
at Router (/Users/ricardobarata/dev/repos/multi-state-management-ui/node_modules/react-router/lib/components.tsx:290:13)
at RouterWrapper (/Users/ricardobarata/dev/repos/multi-state-management-ui/src/testUtils/RouterUtils.tsx:10:3)
at printWarning (node_modules/react-dom/cjs/react-dom.development.js:86:30)
at error (node_modules/react-dom/cjs/react-dom.development.js:60:7)
at warnIfUpdatesNotWrappedWithActDEV (node_modules/react-dom/cjs/react-dom.development.js:27589:9)
at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:25508:5)
at dispatchSetState (node_modules/react-dom/cjs/react-dom.development.js:17527:7)
at node_modules/react-hook-form/src/useForm.ts:168:9
at node_modules/react-hook-form/src/useForm.ts:224:9
at node_modules/react-hook-form/src/useForm.ts:395:9 why?
Make sure to do this for all other tests where you are causing state updates.
After making these changes, your tests should no longer throw these warnings/errors.