-
-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client tests appear to be broken on new apps (beta 22) #4065
Comments
https://github.com/blitz-js/blitz/blob/main/packages/blitz-next/src/index-browser.tsx#L83 Could this be the cause? useRouter is being called outside of the RouterContext. |
export const mockRouter: NextRouter = {
basePath: "",
pathname: "/",
route: "/",
asPath: "/",
params: {},
query: {},
isReady: true,
isLocaleDomain: false,
isPreview: false,
push: vi.fn(),
replace: vi.fn(),
reload: vi.fn(),
back: vi.fn(),
prefetch: vi.fn(),
beforePopState: vi.fn(),
events: {
on: vi.fn(),
off: vi.fn(),
emit: vi.fn(),
},
isFallback: false,
forward: vi.fn(),
}
export const BlitzProvider = ({
client = globalThis.queryClient,
contextSharing = false,
dehydratedState,
hydrateOptions,
children,
}: BlitzProviderProps) => {
const router = mockRouter
if (client) {
return (
<RouterContext.Provider value={router}>
<QueryClientProvider
client={client || globalThis.queryClient}
contextSharing={contextSharing}
>
<Hydrate state={dehydratedState} options={hydrateOptions}>
{children}
</Hydrate>
</QueryClientProvider>
</RouterContext.Provider>
)
}
return <RouterContext.Provider value={router}>{children}</RouterContext.Provider>
} Mocking the router instead of using BTW, this mock object comes from Blitz itself. it's used in the toolkit tests: https://github.com/blitz-js/blitz/blob/main/apps/toolkit-app/test/utils.tsx#L77 Shouldn't the public BlitzProvider do the same? |
I think I found something else that is breaking tests right now: JEST_WORKER_ID will be undefined when using vitest. so this will return true and rendering pages with
|
yeah, this code is a bit screwy. We should not be rendering |
the next line is checking for |
The thing is, if |
So according from your first comment @flybayer and if I understood the second issue correctly, the fix here is:
I'd love to work on this after I have a confirmation that this is the intended solution |
^ ended up opening a PR, I believe the solution makes sense. let's see! |
Co-authored-by: Siddharth Suresh <[email protected]> Closes #4065
What is the problem?
In beta 22, the vitest client tests are broken in a new app (
blitz new
).The only frontend test that exists is initially skipped. If I remove the "skip" flag on
test/index.test.tsx
and run the test, it fail with this error:Looks like there's something wrong in
BlitzProvider
. The error happens inside of it, even when trying to render it inside<RouterContext>
.It's a clean install so I believe the scaffold for frontend tests could be broken.
is it possible that the
test/utils
files generated with blitz new is outdated? The file is different from this one I found in Blitz sourcecode: https://github.com/blitz-js/blitz/blob/main/integration-tests/utils/blitz-test-utils.tsxPaste all your error logs here:
What are detailed steps to reproduce this?
blitz new my-app
npm test
oryarn test
Run
blitz -v
and paste the output here:The text was updated successfully, but these errors were encountered: