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

test: remove await from userEvent usage #182

Merged
merged 3 commits into from
Nov 28, 2020
Merged

Conversation

nickserv
Copy link
Member

userEvent is entirely synchronous (except for type's delay option which isn't used), so we should use it without await and encourage users to do the same.

@afontcu
Copy link
Member

afontcu commented Nov 23, 2020

The checkbox group test fails if called synchronously :(

@nickserv
Copy link
Member Author

What should we be using, Vue.nextTick(), flushPromises(), or waitFor()?

@afontcu
Copy link
Member

afontcu commented Nov 23, 2020

What should we be using, Vue.nextTick(), flushPromises(), or waitFor()?

To keep it relevant to Testing Library users… I'd say waitFor? All these options would do the trick, though.

expect(wonderfulRadioInput).toBeChecked()
expect(initialSelectedRating).not.toBeChecked()
await waitFor(() => expect(initialSelectedRating).not.toBeChecked())
Copy link
Member

@afontcu afontcu Nov 28, 2020

Choose a reason for hiding this comment

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

Not 100% sure it's better for users to learn when/why they should use waitFor instead of just awaiting userEvent? (I honestly don't know 😂)

Copy link
Member Author

@nickserv nickserv Nov 28, 2020

Choose a reason for hiding this comment

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

I assume you mean userEvent, not userSelect. I don't think we should encourage users to await click because it's not async, and awaiting it implies that the test code will wait for Vue to render (not necessarily true as far as I understand, because Vue renders asyncronously). Awaiting anything before this line (even await null) will pass the test. So while await userEvent.click(...) is simpler, I don't think it's correct, and await waitFor(...) better expresses that the assertion will pass some time after clicking. Alternatively we could use one of the other functions I suggested or make user event properly asyncronous.

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

deal 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Want to merge this as is, or do you prefer any of the alternatives?

Copy link
Member

Choose a reason for hiding this comment

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

I guess it's fine as is 😃 I wonder if ppl will understand/know the difference between "test is failing because Vue hasn't updated the DOM yet" and "test is failing because my component is actually wrong", but that's something beyond our control (as long as Vue updates async)

Copy link
Member Author

Choose a reason for hiding this comment

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

If we make userEvent async for Vue users, this can be reverted, and "test is failing because Vue hasn't updated the DOM yet" should be more obvious when an await is missing (some linters can even warn you about not awaiting an async function).

@codecov
Copy link

codecov bot commented Nov 28, 2020

Codecov Report

Merging #182 (9c565ef) into master (3dbb1c2) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #182   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          100       100           
  Branches        35        35           
=========================================
  Hits           100       100           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3dbb1c2...9c565ef. Read the comment docs.

@nickserv nickserv merged commit 2312e18 into master Nov 28, 2020
@nickserv nickserv deleted the nickmccurdy-patch-1 branch November 28, 2020 15:28
@github-actions
Copy link

🎉 This PR is included in version 5.6.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Jun 8, 2022

🎉 This PR is included in version 6.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants