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
Issues importing @generouted/react-router/client in jest #145
Comments
Hey @alexander7161, could you provide a Stack blitz example? I'm also wondering why do you need to import |
Thanks for the response! Here's a minimal reproduction: https://stackblitz.com/edit/vitejs-vite-qsba6t?file=src%2Fmain.test.tsx If you run I'm not importing |
Hey @alexander7161, I tried with Could you try // tests/rendering.test.ts
import { expect, test } from '@playwright/test'
test('rendering', async ({ page }) => {
await page.goto('/')
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible()
}) |
But The original use case I had was a jest unit test on a |
I did some more debugging and added a Now I get a different error:
I believe if generouted had a cjs export for See https://stackoverflow.com/questions/53466859/jest-cannot-find-module-from-node-modules |
@alexander7161 If you need to test the rendering as the example you provided — then you'd need to import the When I tried to add the If you actually need to use imports from the Hope that helps, please let me know if you have more questions. |
The thing is I want to use I found a workaround if anyone is running into the same issue. Add these to your {
"transformIgnorePatterns": [
"node_modules/(?!@@generouted)"
],
"moduleNameMapper": {
"@generouted/react-router/client": "<rootDir>/node_modules/@generouted/react-router/dist/client"
}
} This tells jest not to transform generouted (since it's already ESM) and maps |
Glad you had it working with this config. Thanks for sharing the workaround. |
Describe the Bug
Everything is working fine with generouted. However when I try to run jest tests that import a file that imports generouted client hooks I get the following error:
Cannot find module '@generouted/react-router/client' from 'src/router.ts'
Seems to be related to https://stackoverflow.com/questions/53466859/jest-cannot-find-module-from-node-modules/75595580#75595580
Perhaps exporting a cjs version of client would fix it? See
generouted/packages/react-router/package.json
Line 46 in 8939c9d
Generouted Version
1.18.2
Your Example Website or App or Reproduction
N/A
Steps to Reproduce the Bug or Issue
router.ts
in a file that has testsCannot find module '@generouted/react-router/client' from 'src/router.ts'
Expected Behavior
Generouted client should import correctly in commonJS environment
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: