From d9ed972563ff245f6c69fda1414761d0bde05445 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 16 Oct 2023 11:47:34 +0200 Subject: [PATCH] MockedProvider: default `connectToDevTools: false` --- .changeset/lucky-coats-march.md | 7 +++++++ src/testing/react/MockedProvider.tsx | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/lucky-coats-march.md diff --git a/.changeset/lucky-coats-march.md b/.changeset/lucky-coats-march.md new file mode 100644 index 00000000000..e26c21c6cee --- /dev/null +++ b/.changeset/lucky-coats-march.md @@ -0,0 +1,7 @@ +--- +"@apollo/client": patch +--- + +`MockedProvider`: default `connectToDevTools` to `false` in created `ApolloClient` instance. + +This will prevent the mocked `ApolloClient` instance from trying to connect to the DevTools, which would start a `setTimeout` that might keep running after a test has finished. diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index fcc3dfdb217..152be8ce8d1 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -20,6 +20,7 @@ export interface MockedProviderProps { children?: any; link?: ApolloLink; showWarnings?: boolean; + connectToDevTools?: boolean; } export interface MockedProviderState { @@ -45,10 +46,12 @@ export class MockedProvider extends React.Component< resolvers, link, showWarnings, + connectToDevTools = false, } = this.props; const client = new ApolloClient({ cache: cache || new Cache({ addTypename }), defaultOptions, + connectToDevTools, link: link || new MockLink(mocks || [], addTypename, { showWarnings }), resolvers, });