kentcdodds / dom-testing-library-with-anything

Use DOM Testing Library to test any JS framework on TestingJavaScript.com
https://testingjavascript.com/playlists/use-dom-testing-library-to-test-any-js-framework-ae28
Other
227 stars 88 forks source link

Adding await before fireEvent seems to work ok #16

Closed gusaiani closed 4 years ago

gusaiani commented 4 years ago

Hi @kentcdodds,

working on https://testingjavascript.com/lessons/javascript-use-dom-testing-library-with-preact

At the point where you use the custom fireEventAsync, I somewhat randomly left it as await fireEvent, and it worked.

test('renders a counter', async () => {
  const {getByText} = render(<Counter />)
  const counter = getByText('0')

  // This works
  await fireEvent.click(counter)
  expect(counter).toHaveTextContent('1')

  // This still does not work
  fireEvent.click(counter)
  expect(counter).toHaveTextContent('2')
})

As you created fireEvent, it may be a recent change to it, who knows, just thought to mention it.

Cheers!

kentcdodds commented 4 years ago

Hi @gusaiani,

Thanks for mentioning this. Actually, it just happens to work, but it's not officially supported so I don't think we should document it :)

Thanks anyway!