-
Notifications
You must be signed in to change notification settings - Fork 469
Use innerText rather than textContent for label queries. #190
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// query utilities: | ||
import {getByLabelText} from '../' | ||
import document from './helpers/document' | ||
|
||
function getExampleDOM() { | ||
const div = document.createElement('div') | ||
div.innerHTML = ` | ||
<label>Cars | ||
<select> | ||
<option>Volvo</option> | ||
<option>Mercedes</option> | ||
</select> | ||
</label> | ||
<label><span>States</span> | ||
<select> | ||
<option>Damaged</option> | ||
<option>Good</option> | ||
</select> | ||
</label> | ||
<label><input type="checkbox" value="1"> I agree to terms </label> | ||
` | ||
return div | ||
} | ||
|
||
test('elements inside label', () => { | ||
const container = getExampleDOM() | ||
|
||
const element1 = getByLabelText(container, 'Cars') | ||
expect(element1.tagName).toBe('SELECT') | ||
|
||
// this fails because getNodeText function returns incorrect result on JSDOM but it good for browser | ||
// const element2 = getByLabelText(container, 'States'); | ||
// expect(element2.tagName).toBe('SELECT'); | ||
|
||
const element3 = getByLabelText(container, 'I agree to terms') | ||
expect(element3.value).toBe('1') | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ function queryAllLabelsByText( | |
const matcher = exact ? matches : fuzzyMatches | ||
const matchNormalizer = makeNormalizer({collapseWhitespace, trim, normalizer}) | ||
return Array.from(container.querySelectorAll('label')).filter(label => | ||
matcher(label.textContent, label, text, matchNormalizer), | ||
matcher(getNodeText(label), label, text, matchNormalizer), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget that you'll need to update the |
||
) | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lines added temporarily added until switching jest to karma.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait.... Are you attempting to migrate our tests to karma? If so then please don't take the time, it will not be merged.
If you want to add a few tests in karma and leave the existing tests as they are that's fine. The bill of the tests should be in jest, but I'd be happy to have a few tests that run in a real browser with karma.
Just want to make sure we're clear on expectations here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I understand.