Skip to content

fix(tests): Fix flaky cart preview test#114387

Merged
dashed merged 1 commit intomasterfrom
aleal/fix/flaky-cart-preview-test
Apr 29, 2026
Merged

fix(tests): Fix flaky cart preview test#114387
dashed merged 1 commit intomasterfrom
aleal/fix/flaky-cart-preview-test

Conversation

@dashed
Copy link
Copy Markdown
Member

@dashed dashed commented Apr 29, 2026

Summary

  • Identified by claude as the root cause of frontend CI job failures in PR feat(users): Add suspension UI to gsAdmin user details #114354
  • Fixes a flaky test in static/gsApp/views/amCheckout/components/cart.spec.tsx ("Cart > renders preview data")
  • The expect(mockResponse).toHaveBeenCalled() assertion was firing before the Cart component's async preview fetch completed
  • Moved the assertion after the waitFor content check, which guarantees the mock was called

Root Cause

The Cart component has an async dependency chain before fetching preview data:

  1. useBillingDetails() loads async → hasCompleteBillingInfoshouldDisableCheckoutfetchPreview
  2. On initial render, billing details are undefined, so shouldDisableCheckout=true and preview fetch is skipped
  3. Only after billing details load does the preview fetch trigger
  4. findByTestId('summary-item-due-today') can resolve before the preview mock is called, causing the bare toHaveBeenCalled() to fail intermittently

Test plan

  • Ran cart.spec.tsx locally — all 14 tests pass
  • CI passes

Move `expect(mockResponse).toHaveBeenCalled()` after the `waitFor`
content assertion. The Cart component's preview fetch depends on
billing details loading first (async chain), so the mock may not
be called by the time `findByTestId` resolves. Waiting for the
content to appear guarantees the mock was called.
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 29, 2026
@dashed dashed self-assigned this Apr 29, 2026
@dashed dashed marked this pull request as ready for review April 29, 2026 22:54
@dashed dashed requested a review from a team as a code owner April 29, 2026 22:54
@dashed dashed merged commit 572532e into master Apr 29, 2026
69 checks passed
@dashed dashed deleted the aleal/fix/flaky-cart-preview-test branch April 29, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants