Fix jest tests broken with apollo metadata client (#4728)

The tests were broken. It turns out that it is not easy to mock two
apolloClients as apollo only provides "MockedProvider" component to mock
apollo in tests.
MockedProvider Api does not allow us to mock on client level.

For now, I'm defaulting to the base ApolloClient in test mode to avoid
the issue
This commit is contained in:
Charles Bochet
2024-04-01 14:55:28 +02:00
committed by GitHub
parent 8ae6af6bd7
commit 746747ba2b
9 changed files with 16 additions and 41 deletions

View File

@ -1,9 +1,15 @@
import { useContext } from 'react';
import { useApolloClient } from '@apollo/client';
import { ApolloMetadataClientContext } from '../context/ApolloClientMetadataContext';
export const useApolloMetadataClient = () => {
const apolloMetadataClient = useContext(ApolloMetadataClientContext);
const apolloClient = useApolloClient();
if (process.env.NODE_ENV === 'test') {
return apolloClient;
}
return apolloMetadataClient;
};