Open bmanquen opened 8 months ago
Ran into this myself too
I "hack" fixed this by mocking those globally in my jest tests
jest.mock("@vercel/analytics/react", () => ({
Analytics: jest.fn()
}))
jest.mock("@vercel/speed-insights/next", () => ({
SpeedInsights: jest.fn()
}))
But the issue isn't a Next problem, it's that Analytics, etc. are ES6 Packages that JEST can't parse properly. You can find various answers around for ES6 + Jest solutions
I "hack" fixed this by mocking those globally in my jest tests
jest.mock("@vercel/analytics/react", () => ({ Analytics: jest.fn() })) jest.mock("@vercel/speed-insights/next", () => ({ SpeedInsights: jest.fn() }))
But the issue isn't a Next problem, it's that Analytics, etc. are ES6 Packages that JEST can't parse properly. You can find various answers around for ES6 + Jest solutions
I will give this a try, thanks for the info!
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/crimson-wave-5vnmml?file=%2Fapp%2Flayout.tsx%3A10%2C9-10%2C22
To Reproduce
If using the link to the sample code that reproduces the error:
yarn test
and you will see the error.<Analytics />
from thelayout.tsx
page.yarn test
and the test will pass with no errors.Current vs. Expected behavior
I expect adding Vercel Analytics to not affect current working Jest tests. Here is the error I get when running Jest tests after adding Vercel Analytics,![image](https://github.com/vercel/next.js/assets/46684924/14f08b54-983e-4b29-aa6b-cc2e5b2639ea)
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Jest (next/jest)
Additional context
No response