Skip to content

🔧 Resolve Test Suite Failures and URL.canParse Compatibility#91

Merged
cristiantela merged 4 commits intov3-mainfrom
fix/tests
Apr 17, 2026
Merged

🔧 Resolve Test Suite Failures and URL.canParse Compatibility#91
cristiantela merged 4 commits intov3-mainfrom
fix/tests

Conversation

@cristiantela
Copy link
Copy Markdown
Collaborator

Description

Type of Change

    • Bugfix
    • Feature
    • Code style update (formatting, local variables)
    • Refactoring (no functional changes, no api changes)
    • Tests
    • Other

Motivation and Context

The test suite had several failures caused by outdated assertions, incomplete mock contexts, incorrect method call types (instance vs. static), and a misconfigured Jest module resolver. Additionally, URL.canParse is not available in the jsdom test environment or in older runtimes, causing runtime errors. These issues were preventing the test suite from running cleanly.

Summary of Changes

  • src/components/Product/InlineProduct.jsx — Replaced URL.canParse() with a try/catch block using new URL(), which is universally supported across all environments including jsdom
  • jest.config.js — Moved the SVG moduleNameMapper rule before the @/ alias rule so that imports like @/assets/icons/foo.svg?react are correctly intercepted before the alias resolver tries to treat ?react as part of the file path
  • src/components/ConversationStarters/ConversationStarters.test.jsx — Updated assertion from .weni-button to .weni-fs-button to reflect the component's migration from Button to FSButton
  • src/views/Cart.test.jsx — Added missing config field to the useChatContext mock return value, preventing a TypeError when CounterControls accesses config.addToCart
  • test/services/voice/AudioCapture.test.js — Fixed requestPermission() and checkPermission() calls to use AudioCapture as the receiver (static methods), not a class instance; consolidated redundant describe block
  • test/components/VoiceMode/VoiceModeButton.test.jsx and VoiceModeError.test.jsx — Removed manual @/utils/icons Proxy mocks that were unnecessary since moduleNameMapper already handles all SVG imports globally, and were causing ReferenceError due to Jest's jest.mock hoisting behavior

URL.canParse is not available in the jsdom test environment and older
runtimes. Using try/catch with new URL() achieves the same behavior.

Made-with: Cursor
The SVG rule must come before the generic @/ alias so that imports like
@/assets/icons/foo.svg?react are intercepted before the alias tries to
resolve the ?react query suffix as a real file path.

Made-with: Cursor
- Update ConversationStarterButton test to assert weni-fs-button class
  after component was migrated from Button to FSButton
- Add missing config field to Cart test mock context to prevent
  TypeError when CounterControls accesses config.addToCart

Made-with: Cursor
- Call AudioCapture.requestPermission() and checkPermission() as static
  methods; instance calls were causing TypeError
- Remove manual @/utils/icons mock from VoiceMode tests since
  moduleNameMapper already handles all SVG imports globally

Made-with: Cursor
@cristiantela cristiantela requested a review from Aldemylla as a code owner April 17, 2026 18:38
@cristiantela cristiantela requested review from paulobernardoaf and removed request for Aldemylla April 17, 2026 18:38
@cristiantela cristiantela merged commit a5ab7a9 into v3-main Apr 17, 2026
2 checks passed
@cristiantela cristiantela deleted the fix/tests branch April 17, 2026 21:02
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.

2 participants