Module Augmentation for Playwright's Page Type in Vitest Browser Commands #7743
mikaelbalin
started this conversation in
Feedback
Replies: 1 comment 1 reply
-
|
Vitest actually exposes a way to augment commands types depending on the provider: https://vitest.dev/guide/browser/playwright.html You need to either add |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've been working with Vitest and Playwright for browser testing and discovered that the TypeScript types for browser commands don't properly include the
pageproperty from Playwright. This makes it difficult to create custom browser commands that need access to Playwright's Page API.I solved this by augmenting the module types in my
vitest.config.mts:This allows me to create browser commands like:
According to the documentation, we should generally avoid it as it can break things. However, in this case, it's extremely useful for creating type-safe browser commands.
Should Vitest better expose these types directly in their public API?
I'd appreciate any insights or alternative approaches!
Beta Was this translation helpful? Give feedback.
All reactions