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

feat(browser): support click event #5777

Merged
merged 10 commits into from
Jun 3, 2024

Conversation

sheremet-va
Copy link
Member

@sheremet-va sheremet-va commented May 25, 2024

Description

Addresses #5770

This PR only implements click method on userEvent:

import { userEvent } from '@vitest/browser/context'
import { expect, test, vi } from 'vitest'

test('clicks on an element', async () => {
  const button = document.createElement('button')
  button.textContent = 'Hello World'
  const fn = vi.fn()
  button.onclick = () => {
    fn()
  }
  document.body.appendChild(button)

  await userEvent.click(button)
  expect(fn).toHaveBeenCalled()
})

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:.

@sheremet-va sheremet-va marked this pull request as draft May 25, 2024 09:21
@sheremet-va sheremet-va force-pushed the feat/interactivity-api-poc branch from 400986c to 3bcd9f6 Compare June 3, 2024 07:33
@sheremet-va sheremet-va changed the title feat: browser userEvent proof of concept feat(browser): support click even Jun 3, 2024
@sheremet-va sheremet-va changed the title feat(browser): support click even feat(browser): support click event Jun 3, 2024
@sheremet-va sheremet-va marked this pull request as ready for review June 3, 2024 08:50
@sheremet-va sheremet-va merged commit 839c39f into vitest-dev:main Jun 3, 2024
15 of 16 checks passed
@sheremet-va sheremet-va deleted the feat/interactivity-api-poc branch June 3, 2024 10:07
@charlieforward9
Copy link

Is the userEvent.type command supported in browser mode yet? We are having an issue running our SearchBar test.

@sheremet-va
Copy link
Member Author

Is the userEvent.type command supported in browser mode yet? We are having an issue running our SearchBar test.

Only click event is supported at the moment as you can see in the title of this PR.

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