You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.
Hey, I have a login component, which replaces URL if there is a specific hash inside it. It's made with the help of useNavigate hook, so in my test all I wanted to do is to mock its implementation and spy on a passed callback function:
But as soon I mock @remix-run/react I get a few errors in the console, which I don't think are fully related to what's going on in the test but rather to the fact, that insted of <Login /> component an erroor boundary is being rendered:
Error: Uncaught [TypeError: __vite_ssr_import_0__.useMatches is not a functionor its return value is not iterable]
at reportException (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
at innerInvokeEventListeners (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:353:9)
at invokeEventListeners (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3)
at HTMLUnknownElementImpl._dispatch (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9)
at HTMLUnknownElementImpl.dispatchEvent (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17)
at HTMLUnknownElement.dispatchEvent (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34)
at Object.invokeGuardedCallbackDev (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:4213:16)
at invokeGuardedCallback (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:4277:31)
at beginWork$1 (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:27451:7)
at performUnitOfWork (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:26560:12) TypeError: __vite_ssr_import_0__.useMatches is not a functionor its return value is not iterable
at Module.useSession (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/app/hooks/useSession.ts:4:45)
at Login (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/app/components/login.tsx:34:41)
at renderWithHooks (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:16305:18)
at mountIndeterminateComponent (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:20074:13)
at beginWork (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:21587:16)
at HTMLUnknownElement.callCallback (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:4164:14)
at HTMLUnknownElement.callTheUserObjectsOperation (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
at innerInvokeEventListeners (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25)
at invokeEventListeners (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3)
at HTMLUnknownElementImpl._dispatch (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9)
TypeError: __vite_ssr_import_0__.useMatches is not a functionor its return value is not iterable
at Module.useSession (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/app/hooks/useSession.ts:4:45)
at Login (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/app/components/login.tsx:34:41)
at renderWithHooks (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:16305:18)
at mountIndeterminateComponent (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:20074:13)
at beginWork (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:21587:16)
at beginWork$1 (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:27426:14)
at performUnitOfWork (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:26560:12)
at workLoopSync (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:26466:5)
at renderRootSync (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:26434:7)
at performConcurrentWorkOnRoot (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:25738:74)
Warning: validateDOMNesting(...): <html> cannot appear as a child of <div>.
at html
at RemixRootDefaultErrorBoundary (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/@remix-run/react/dist/errorBoundaries.js:80:3)
at RemixErrorBoundary (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/@remix-run/react/dist/errorBoundaries.js:24:5)
at RemixEntry (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/@remix-run/react/dist/components.js:56:12)
at RemixStub (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/test/create-remix-stub.tsx:22:5)
Error: Uncaught [TypeError: __vite_ssr_import_0__.useMatches is not a functionor its return value is not iterable]
at reportException (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
at innerInvokeEventListeners (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:353:9)
at invokeEventListeners (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3)
at HTMLUnknownElementImpl._dispatch (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9)
at HTMLUnknownElementImpl.dispatchEvent (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17)
at HTMLUnknownElement.dispatchEvent (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34)
at Object.invokeGuardedCallbackDev (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:4213:16)
at invokeGuardedCallback (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:4277:31)
at beginWork$1 (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:27451:7)
at performUnitOfWork (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:26560:12) TypeError: __vite_ssr_import_0__.useMatches is not a functionor its return value is not iterable
at Module.useSession (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/app/hooks/useSession.ts:4:45)
at Login (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/app/components/login.tsx:34:41)
at renderWithHooks (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:16305:18)
at mountIndeterminateComponent (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:20074:13)
at beginWork (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:21587:16)
at HTMLUnknownElement.callCallback (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:4164:14)
at HTMLUnknownElement.callTheUserObjectsOperation (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
at innerInvokeEventListeners (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25)
at invokeEventListeners (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3)
at HTMLUnknownElementImpl._dispatch (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9)
TypeError: __vite_ssr_import_0__.useMatches is not a functionor its return value is not iterable
at Module.useSession (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/app/hooks/useSession.ts:4:45)
at Login (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/app/components/login.tsx:34:41)
at renderWithHooks (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:16305:18)
at mountIndeterminateComponent (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:20074:13)
at beginWork (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:21587:16)
at beginWork$1 (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:27426:14)
at performUnitOfWork (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:26560:12)
at workLoopSync (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:26466:5)
at renderRootSync (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:26434:7)
at recoverFromConcurrentError (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/react-dom/cjs/react-dom.development.js:25850:20)
The above error occurred in the <Login> component:
at Login (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/app/components/login.tsx:34:41)
at TestSubject
at default
at RemixRoute (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/@remix-run/react/dist/components.js:195:3)
at Routes (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/@remix-run/react/dist/components.js:172:7)
at Router (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/@remix-run/react/node_modules/react-router/umd/react-router.development.js:821:17)
at RemixCatchBoundary (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/@remix-run/react/dist/errorBoundaries.js:127:10)
at RemixErrorBoundary (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/@remix-run/react/dist/errorBoundaries.js:24:5)
at RemixEntry (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/node_modules/@remix-run/react/dist/components.js:56:12)
at RemixStub (/Users/mateusz.kwiatkowski/Playground/remix-proste-opowiesci/test/create-remix-stub.tsx:22:5)
React will try to recreate this component tree from scratch using the error boundary you provided, RemixErrorBoundary.
And if I try something like this: vi.spyOn(RemixRouter, "useNavigate").mockImplementation(navigate) the whole test executions seems to take ages, probably, due to some internal error of infinite loop created with the spyOn call.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey, I have a login component, which replaces URL if there is a specific hash inside it. It's made with the help of
useNavigate
hook, so in my test all I wanted to do is to mock its implementation and spy on a passed callback function:But as soon I mock
@remix-run/react
I get a few errors in the console, which I don't think are fully related to what's going on in the test but rather to the fact, that insted of<Login />
component an erroor boundary is being rendered:And if I try something like this:
vi.spyOn(RemixRouter, "useNavigate").mockImplementation(navigate)
the whole test executions seems to take ages, probably, due to some internal error of infinite loop created with the spyOn call.Is there other proper way of doing such things?
Beta Was this translation helpful? Give feedback.
All reactions