storybookjs / testing-library

Instrumented version of Testing Library for Storybook Interactions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Breaks vitest - The current testing environment is not configured to support act(...)

viveleroi opened this issue · comments

Describe the bug
We use vitest with testing-library/react for our component tests. While upgrading dependencies recently, something broke all of our tests and I've narrowed it down to this plugin, despite the fact that we don't even use it.

In all of our component tests, we have an import like this:

import { act, fireEvent, render, screen } from '@testing-library/react'

Then, a test uses it like so:

it('calls the onClick handler', async () => {
  const user = userEvent.setup()

  const spiedOnClick = vi.fn()
  render(<DropdownButton menu={menu} onClick={spiedOnClick} text='Submit' />)

  await act(async () => {
    await user.click(screen.getByRole('button'))
  })

  expect(spiedOnClick).toHaveBeenCalled()
})

However, when upgrading from @storybook/testing-library 0.1.0 to 0.2.0, every test that uses the above import fails:

Warning: The current testing environment is not configured to support act(...)

Expected behavior
This was not an error in 0.1.0.

Screenshots
If applicable, add screenshots to help explain your problem.

System
Environment Info:

System:
OS: Windows 10 10.0.22621
CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
Binaries:
Node: 18.17.0 - C:\Program Files\nodejs\node.EXE
Yarn: 3.4.1 - C:\Program Files\nodejs\yarn.CMD
npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22621.1992.0), Chromium (115.0.1901.188)
npmPackages:
@storybook/addon-docs: 7.0.11 => 7.0.11
@storybook/addon-essentials: 7.0.11 => 7.0.11
@storybook/addon-interactions: 7.0.11 => 7.0.11
@storybook/addon-links: 7.0.11 => 7.0.11
@storybook/addon-mdx-gfm: 7.0.11 => 7.0.11
@storybook/react: 7.0.11 => 7.0.11
@storybook/react-vite: 7.0.11 => 7.0.11
@storybook/testing-library: 0.2.0 => 0.2.0