Skip to content

docs: add guidance on testing suspense hooks with MockedProvider#13291

Merged
jerelmiller merged 5 commits into
mainfrom
copilot/fix-mockedprovider-suspense-query
Jun 30, 2026
Merged

docs: add guidance on testing suspense hooks with MockedProvider#13291
jerelmiller merged 5 commits into
mainfrom
copilot/fix-mockedprovider-suspense-query

Conversation

Copilot AI commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Components using useSuspenseQuery permanently hang in tests with MockedProvider unless render is wrapped in await act(). Unlike useQuery, suspense hooks suspend the component immediately — the test never advances without act to drive React through the suspend/resume cycle.

Changes

  • docs/source/development-testing/testing.mdx — adds a "Testing with Suspense" section explaining the behavioral difference between useQuery and useSuspenseQuery in tests, with a full working example:
it("should render the greeting", async () => {
  await act(() =>
    render(
      <MockedProvider mocks={mocks}>
        <Suspense fallback={<div>Loading...</div>}>
          <Greeting />
        </Suspense>
      </MockedProvider>
    )
  );

  expect(await screen.findByText("Hello")).toBeInTheDocument();
});

Without await act(), the Suspense fallback renders and never resolves. This is not a MockLink bug — Apollo's SuspenseCache keeps the subscription alive; the missing piece is act to let React process the suspend/resume cycle.

@apollo-cla

Copy link
Copy Markdown

@copilot: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@apollo-librarian

apollo-librarian Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 1 changed, 0 removed
* (developer-tools)/react/(latest)/development-testing/testing.mdx

Build ID: c25e1f72d733e716f5692547
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/c25e1f72d733e716f5692547


⚠️ AI Style Review — 2 Issues Found

Summary

The documentation has been updated to align with the style guide across three key sections. Under structural elements, headings were updated to sentence case, specifically treating 'suspense' as a common noun. For framing Apollo products, the narrative was shifted to emphasize the benefits of the suspense approach over the limitations of previous methods. Finally, language was improved for global accessibility by replacing the idiom 'in flight' with clearer terms like 'active' or 'processing'.

Duration: 3749ms
Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b318a37

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI and others added 2 commits June 26, 2026 11:05
Co-authored-by: phryneas <4282439+phryneas@users.noreply.github.com>
Co-authored-by: phryneas <4282439+phryneas@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix MockedProvider suspension issue with useSuspenseQuery in tests docs: add guidance on testing suspense hooks with MockedProvider Jun 26, 2026
Copilot AI requested a review from phryneas June 26, 2026 11:06
Comment thread docs/source/development-testing/testing.mdx Outdated
@pkg-pr-new

pkg-pr-new Bot commented Jun 26, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@apollo/client@13291

commit: b318a37

@jerelmiller jerelmiller marked this pull request as ready for review June 30, 2026 17:32
@jerelmiller jerelmiller requested a review from a team as a code owner June 30, 2026 17:32
@jerelmiller jerelmiller merged commit 61b6c00 into main Jun 30, 2026
46 checks passed
@jerelmiller jerelmiller deleted the copilot/fix-mockedprovider-suspense-query branch June 30, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants