Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): make parameters non-nullable for Playwright options #6989

Conversation

apple-yagi
Copy link
Contributor

Description

Currently, when selecting Playwright as the provider, type completion for the options parameter of the click method from @vitest/browser/context's userEvent is not working. This is because when fetching the types for Playwright's options, the possibility of undefined is not eliminated, resulting in a missing interface type. Therefore, I have wrapped it with NonNullable to remove the potential for undefined, which fixes the issue so that type completion now works.

before

スクリーンショット 2024-11-30 17 47 47

after

スクリーンショット 2024-11-30 17 46 40

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Nov 30, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7b7fa53
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/674ad149aa88230008e7e3ea
😎 Deploy Preview https://deploy-preview-6989--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -16,7 +16,7 @@ export const hover: UserEventCommand<UserEvent['hover']> = async (
}
else if (context.provider instanceof WebdriverBrowserProvider) {
const browser = context.browser
await browser.$(selector).moveTo(options)
await browser.$(selector).moveTo(options as any)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref:

await browser.$(selector).click(options as any)

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Dec 1, 2024

Thanks for the PR 👋

The fix seems right but can you provide a reproduction to better understand the issue?

For me locally, I get an error like this in this reproduction https://github.com/hi-ogawa/reproductions/tree/main/vitest-browser-playwright-types,

screenshot1

image

but the error somehow went away and I get a correct completion once I added a proper tsconfig.json:

screenshot2

image

@hi-ogawa hi-ogawa mentioned this pull request Dec 1, 2024
6 tasks
@apple-yagi
Copy link
Contributor Author

@hi-ogawa Thank you for your reply!

I have a question: what are the settings of the tsconfig.json you added? I suspect that the noUncheckedIndexedAccess option might be the cause.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Dec 1, 2024

Oh, that's a good point. I didn't even have strict: true 😅 After adding that I get the error like screenshot1.

I'm adding dts test in #6995 with skipLibCheck: false and that shows an error too now. We'll merge your PR first. Thanks for the contribution!

@hi-ogawa hi-ogawa merged commit fe2a187 into vitest-dev:main Dec 1, 2024
17 checks passed
@apple-yagi apple-yagi deleted the fix-playwright-user-event-options-interface branch December 1, 2024 10:10
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