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: Add toHaveDisplayValue() matcher #223

Merged
merged 13 commits into from Apr 9, 2020

Conversation

cloud-walker
Copy link
Contributor

What:

Add .toHaveDisplayValue() custom matcher as discussed here: #221

Checklist:

  • Documentation
  • Tests
  • Updated Type Definitions
  • Ready to be merged

@cloud-walker
Copy link
Contributor Author

I've little experience with typescript, not sure if I should do something about type definitions 🤔

@codecov
Copy link

codecov bot commented Mar 24, 2020

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #223   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        20    +1     
  Lines          257       268   +11     
  Branches        62        65    +3     
=========================================
+ Hits           257       268   +11     
Impacted Files Coverage Δ
src/to-have-display-value.js 100.00% <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 779448f...5e37a9e. Read the comment docs.

@eps1lon eps1lon changed the title Introduce .toHaveDisplay() custom matcher feat: Add toHaveDisplayValue() matcher Mar 25, 2020
@eps1lon eps1lon added the enhancement New feature or request label Mar 25, 2020
README.md Outdated Show resolved Hide resolved
@alexkrolick
Copy link
Contributor

alexkrolick commented Mar 26, 2020

This looks like it only supports select tags so far. Would you be open to making it work the same way as the byDisplayValue query? It works with other form elements.

Returns the input, textarea, or select element that has the matching display value.

@cloud-walker
Copy link
Contributor Author

Hi, @alexkrolick I think it's a good idea, it could be a twin matcher with toHaveValue but for the display values.

But I was wondering if do the extra work in another PR instead of adding more changes to this one 🤔

@gnapse
Copy link
Member

gnapse commented Mar 26, 2020

But I was wondering if do the extra work in another PR instead of adding more changes to this one

@cloud-walker I'd rather have it all at once, even if it takes longer. The reason being that the PR merge triggers a new release, and I'd rather have this feature released in its entirety.

This does not imply any pressure. Take your time, the same time you would've take to make the other PR.

Good work here overall, and thanks! Also thanks to @eps1lon for stepping in and reviewing.

@cloud-walker
Copy link
Contributor Author

cloud-walker commented Mar 26, 2020

Ok, input and textarea support added, I've excluded type=radio and type=checkbox, as they don't have a display value 🤔

@cloud-walker
Copy link
Contributor Author

Hi all, any news from this PR? 👀

Copy link
Member

@gnapse gnapse left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

I left some comments of things still needed to be addressed. Let me know what you think about these.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Comment on lines +13 to +14
expect(queryByTestId('select')).toHaveDisplayValue('Select a fruit...')
expect(queryByTestId('select')).not.toHaveDisplayValue('Banana')
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice if the test also covered the case of changing the selected option programmatically to banana and then check that toHaveDisplayValue('Banana') pass.

And maybe do it for the other cases as well (textarea and input).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, I'm wondering why the repository is not using fireEvent from the testing-library core (or even userEvent) 🤔

README.md Outdated Show resolved Hide resolved
src/to-have-display-value.js Show resolved Hide resolved
cloud-walker and others added 5 commits April 9, 2020 17:50
Co-Authored-By: Ernesto García <gnapse@gmail.com>
Co-Authored-By: Ernesto García <gnapse@gmail.com>
Co-Authored-By: Ernesto García <gnapse@gmail.com>
@gnapse gnapse merged commit 840414f into testing-library:master Apr 9, 2020
@gnapse
Copy link
Member

gnapse commented Apr 9, 2020

@all-contributors add @cloud-walker for code, test, ideas

@allcontributors
Copy link
Contributor

@gnapse

I've put up a pull request to add @cloud-walker! 🎉

@gnapse
Copy link
Member

gnapse commented Apr 9, 2020

🎉 This PR is included in version 5.5.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
enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants