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

feat: allow selecting options by nodes #297

Merged
merged 3 commits into from May 26, 2020

Conversation

dougbacelar
Copy link
Contributor

What:
Allow selection of combobox options by html nodes. e.g.

render(
    <select>
      <option value="1">first option</option>
    </select>,
  )
userEvent.selectOptions(screen.getByRole('combobox'), screen.getByText('first option'))

Why:

Since users don't directly interact with option values, this should allow for testing in a more user-like way.

How:
In addition to checking for the option.value string, now it also checks if the node itself is in the given array.

Checklist:

  • Documentation
  • Tests
  • Typings
  • Ready to be merged

Comments:
Ideally, I think userEvent.selectOptions should receive option text instead of option values, and warn if it can't find the given option.text.

Since that would be a breaking change, I think this PR could be a good first step towards that direction.

Related to:

@codecov
Copy link

codecov bot commented May 26, 2020

Codecov Report

Merging #297 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #297   +/-   ##
=======================================
  Coverage   98.90%   98.90%           
=======================================
  Files           1        1           
  Lines         182      182           
  Branches       55       56    +1     
=======================================
  Hits          180      180           
  Misses          2        2           
Impacted Files Coverage Δ
src/index.js 98.90% <100.00%> (ø)

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 6239c3a...18f1021. Read the comment docs.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Totally reasonable 👍

@kentcdodds kentcdodds merged commit 41f71b5 into testing-library:master May 26, 2020
@kentcdodds
Copy link
Member

@all-contributors please add @dougbacelar for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @dougbacelar! 🎉

@kentcdodds
Copy link
Member

🎉 This PR is included in version 10.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jsphstls
Copy link

Thank you @dougbacelar !

@bullishgopher
Copy link

This is cool. Thank you @dougbacelar !

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.

None yet

4 participants