Skip to content

Spike/add interaction#158

Merged
TintoSoft merged 15 commits into
masterfrom
spike/add-interaction
Oct 20, 2025
Merged

Spike/add interaction#158
TintoSoft merged 15 commits into
masterfrom
spike/add-interaction

Conversation

@TintoSoft

@TintoSoft TintoSoft commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

🎩 What?

Added full support and generic typing for centralized interactions in Wrapito (e.g., @testing-library/user-event), including:

New/updated generic types:

  • InteractionOptions<UserLib, UserInstance, UserSetupOptions>
  • WrapOptions<UserSetupOptions>
  • Config<UserLib, UserInstance, UserSetupOptions>
  • Wrap<UserLib, UserInstance, UserSetupOptions>

API:

  • withInteraction(config) now accepts typed options (SetupOptions) per test.
  • mount() now also returns user?: Instance, the typed instance of the interaction library.

Implementation:

  • withInteraction is typed and updated to store interactionConfig in options.
  • getMount retrieves the interaction from getConfig() and generates user using interaction.setup(lib, config) if defined; otherwise, it exposes the lib directly.

Consumer typing:

  • Example and recommendation for global.d.ts (or project types) to declare a specialized Wrap with UserEvent or any other interaction library, so that user has proper typing and autocompletion in tests.

🤔 Why?

Before:

With userEvent v14, each test required manually executing userEvent.setup(). This implied:

  • Importing the library in each test.
  • Running setup() for each test.
  • Not being able to provide global configuration options (e.g., advanceTimers in tests with fake timers).

Now:

  • The setup can be centrally configured in Wrapito's configure().
  • Tests that need specific configuration can pass it via withInteraction().
  • This centralizes and simplifies userEvent setup.
  • It also allows using other interaction libraries, such as fireEvent, with the same API and safe typing.

🧪 How to use it

Setup

image

Test example

image

Declare global

image

@TintoSoft TintoSoft requested a review from a team as a code owner October 2, 2025 13:53
Comment thread src/models.ts Outdated
Comment thread src/models.ts Outdated
@TintoSoft TintoSoft merged commit 8e8745b into master Oct 20, 2025
1 check passed
@TintoSoft TintoSoft deleted the spike/add-interaction branch October 20, 2025 09:58
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