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: implement toHaveSelection #637

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

silviuaavram
Copy link
Contributor

What:
Implement toHaveSelection.

Why:
Closes #289.

How:
Based on #412.

Differences from original PR:

  • changed the partial selection condition a little bit to help with testing:
else {
    // Element is partially selected
    const selectionStartsWithinElement =
      element === originalRange.startContainer ||
      element.contains(originalRange.startContainer)
    const selectionEndsWithinElement =
      element === originalRange.endContainer ||
      element.contains(originalRange.endContainer)
    selection.removeAllRanges()

    if (selectionStartsWithinElement || selectionEndsWithinElement) {
      temporaryRange.selectNodeContents(element)

      if (selectionStartsWithinElement) {
        temporaryRange.setStart(
          originalRange.startContainer,
          originalRange.startOffset,
        )
      }
      if (selectionEndsWithinElement) {
        temporaryRange.setEnd(
          originalRange.endContainer,
          originalRange.endOffset,
        )
      }

      selection.addRange(temporaryRange)
    }
  }
  • added a few more asserts to the tests.
  • types
  • documentation

Checklist:

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

@silviuaavram
Copy link
Contributor Author

Hey @gnapse could you help me with a review here, please? Thanks!

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.

Thanks!

README.md Outdated Show resolved Hide resolved
@gnapse
Copy link
Member

gnapse commented Oct 16, 2024

@all-contributors please add @silviuaavram for code, test

Copy link
Contributor

@gnapse

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

This was referenced Oct 16, 2024
@gnapse gnapse merged commit 9b14804 into testing-library:main Oct 16, 2024
5 checks passed
Copy link

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

toHaveSelectionValue
2 participants