Skip to content
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

MockedProvider: default connectToDevTools: false #11289

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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