Skip to content

Conversation

@jeanchung
Copy link
Contributor

@jeanchung jeanchung commented Aug 18, 2019

What:
Fixes #117, adds a test for this use case, and adds me as a contributor.

Why:
The getSelectValue() util was using selectedOptions to get the selected options for a select. Because selectedOptions is not a reactive property, this was causing a bug where toHaveFormValues() would not recognize changed select values.

How:
This PR updates getSelectValue() to use options rather than selectedOptions, then filter for the selected options, similar to the way this was fixed in dom-testing-library (as suggested in the issue).

Checklist:

  • Documentation N/A
  • Tests
  • Updated Type Definitions N/A
  • Ready to be merged

@weyert
Copy link

weyert commented Aug 18, 2019

Thank you for your contribution 💃

return items.map(mapper).join('')
}

/* eslint max-lines-per-function:0 */
Copy link

Choose a reason for hiding this comment

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

Just wondering why this is added?

Copy link
Contributor Author

@jeanchung jeanchung Aug 18, 2019

Choose a reason for hiding this comment

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

The linter was throwing this error on line 108 due to the length of tests for toHaveFormValues():

Screen Shot 2019-08-18 at 2 56 59 PM

I noticed that this test file handled this problem this way, so I did the same. Let me know if another solution is preferred here!

Copy link

Choose a reason for hiding this comment

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

Ah alright, seems fair. Guess, we could split it up. I think @kentcdodds wrote an article about avoiding nesting: https://kentcdodds.com/blog/avoid-nesting-when-youre-testing

return items.map(mapper).join('')
}

/* eslint max-lines-per-function:0 */
Copy link

Choose a reason for hiding this comment

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

Ah alright, seems fair. Guess, we could split it up. I think @kentcdodds wrote an article about avoiding nesting: https://kentcdodds.com/blog/avoid-nesting-when-youre-testing

@gnapse gnapse merged commit 170b5ed into testing-library:master Aug 19, 2019
@gnapse
Copy link
Member

gnapse commented Aug 19, 2019

🎉 This PR is included in version 4.0.1 🎉

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.

<select> element value change is not recognized properly by toHaveFormValues

3 participants