Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: remove await from userEvent usage #182

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

Merged
nickserv merged 3 commits into master from nickmccurdy-patch-1
Nov 28, 2020
Merged

Conversation

@nickserv
Copy link
Member

@nickserv nickserv commented Nov 23, 2020

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.

Copy link
Member

afontcu commented Nov 23, 2020

The checkbox group test fails if called synchronously :(

Copy link
Member Author

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

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.

userEvent.click(wonderfulRadioInput)
expect(wonderfulRadioInput).toBeChecked()
expect(initialSelectedRating).not.toBeChecked()
awaitwaitFor(()=>expect(initialSelectedRating).not.toBeChecked())
Copy link
Member

@afontcu afontcu Nov 28, 2020
edited
Loading

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
edited
Loading

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

Copy link

codecov bot commented Nov 28, 2020
edited
Loading

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.

Copy link

🎉 This PR is included in version 5.6.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Reviewers

@afontcu afontcu afontcu approved these changes

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /