-
Notifications
You must be signed in to change notification settings - Fork 392
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
fix: issue with Node.textContent returning text in comment nodes #1461
Merged
Merged
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 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 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
49 changes: 49 additions & 0 deletions
49
packages/integration-karma/test/polyfills/text-content/index.spec.js
This file contains 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,49 @@ | ||
import { createElement } from 'lwc'; | ||
import XTest from 'x/test'; | ||
|
||
describe('Node.textContent', () => { | ||
it('should not return comment text when Node.nodeType is ELEMENT_NODE', () => { | ||
const elm = document.createElement('div'); | ||
elm.innerHTML = | ||
'<div>' + | ||
'<!-- Some comment -->' + | ||
'text content' + | ||
'<!-- Some other comment -->' + | ||
'</div>'; | ||
|
||
expect(elm.textContent).toBe('text content'); | ||
}); | ||
|
||
it('should not return comment text from 2nd level ELEMENT_NODE', () => { | ||
const elm = document.createElement('div'); | ||
|
||
elm.innerHTML = | ||
'<div>' + | ||
'<!-- Some comment -->' + | ||
'text content' + | ||
'<div>' + | ||
'<!-- 2nd level comment -->' + | ||
'2nd level text' + | ||
'</div>' + | ||
'<!-- Some other comment -->' + | ||
'</div>'; | ||
|
||
expect(elm.textContent).toBe('text content2nd level text'); | ||
}); | ||
|
||
it('should return comment text when Node.nodeType is COMMENT_NODE', () => { | ||
const elm = document.createComment('Some comment'); | ||
|
||
expect(elm.textContent).toBe('Some comment'); | ||
}); | ||
|
||
it('should not return comment text from the shadowRoot', () => { | ||
const elm = createElement('x-parent', { is: XTest }); | ||
document.body.appendChild(elm); | ||
|
||
// since we remove the comments from the template, we need to add it manually | ||
elm.shadowRoot.appendChild(document.createComment('Some comment')); | ||
|
||
expect(elm.shadowRoot.textContent).toBe('text content'); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
packages/integration-karma/test/polyfills/text-content/x/test/test.html
This file contains 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,4 @@ | ||
<template> | ||
<!-- This is a comment, it should not be part of the textContent --> | ||
text content | ||
</template> |
3 changes: 3 additions & 0 deletions
3
packages/integration-karma/test/polyfills/text-content/x/test/test.js
This file contains 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,3 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Test extends LightningElement {} |
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.
add another test that has the context in the second level, not as a root element, just to make sure that we cover that too.