-
Notifications
You must be signed in to change notification settings - Fork 36
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
Jest registerApolloClient is not a function #353
Comments
Jest simulates a browser environment, so it uses the wrong version of Apollo Client for this - You can do /** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-server'],
},
}; in your jest config, which will instead load the "server component" code of |
@phryneas I'm getting the same error using Vitest, and I've been trying to replicate the provided Jest config without luck. Any pointers? |
Vitest also doesn't simulate a For vitest, you would have to specify export default defineConfig({
plugins: [react()],
resolve: {
conditions: ["react-server"],
},
}); |
Thanks for helping, but adding that line to the config seems to break all tests with the following error:
|
Yes, you are running your tests with React 18.3.1, while Next.js is using a Canary build of React. You will have to find out which React build your Next.js installation uses and use that same build for your tests. Next.js ignores your Look in |
That is quite insane indeed, I gave the last suggestion a shot but no luck. I think I'll wait with adding tests for the few pages I've migrated to app router until Next 15 to see if they make this more manageable. Thanks for your help! |
I've followed the recommendations from the README, but I get this error during tests:
Apart from jest the code works fine.
Repo to reproduce:
https://github.com/levchenkod/next-apolo-jest-basic-setup
The text was updated successfully, but these errors were encountered: