Skip to content

Button clicks not working when using custom container #58

@ConsoleTVs

Description

@ConsoleTVs
it.concurrent('test', async ({ expect }) => {
  const container = document.createElement('div')
  let value = false

  const result = render(
    () => {
      function doStuff() {
        console.log('hello, world!')
        value = true
      }

      return <button onClick={doStuff} />
    },
    { container }
  )

  const button = result.getByRole('button')

  fireEvent.click(button)

  expect(value).toBe(true)
})

Using vitest, the button event is not fired when using a custom container. When not specified, the event works just fine:

it.concurrent('test', async ({ expect }) => {
  let value = false

  const result = render(
    () => {
      function doStuff() {
        console.log('hello, world!')
        value = true
      }

      return <button onClick={doStuff} />
    }
  )

  const button = result.getByRole('button')

  fireEvent.click(button)

  expect(value).toBe(true)
})

However, I prefer to have tests isolated as they can run concurrently. This works in other frameworks such as react testing lib.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions