Skip to content

Commit

Permalink
MockedProvider: default connectToDevTools: false (#11289)
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas authored Oct 16, 2023
1 parent 2be7eaf commit b5894db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .api-reports/api-report-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ export interface MockedProviderProps<TSerializedCache = {}> {
childProps?: object;
// (undocumented)
children?: any;
// (undocumented)
connectToDevTools?: boolean;
// Warning: (ae-forgotten-export) The symbol "DefaultOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down
7 changes: 7 additions & 0 deletions .changeset/lucky-coats-march.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions src/testing/react/MockedProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export interface MockedProviderProps<TSerializedCache = {}> {
children?: any;
link?: ApolloLink;
showWarnings?: boolean;
/**
* If set to true, the MockedProvider will try to connect to the Apollo DevTools.
* Defaults to false.
*/
connectToDevTools?: boolean;
}

export interface MockedProviderState {
Expand All @@ -45,10 +50,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,
});
Expand Down

0 comments on commit b5894db

Please sign in to comment.