Skip to content

Commit

Permalink
Always use textContent instead of innerText
Browse files Browse the repository at this point in the history
  • Loading branch information
philippbosch committed Aug 29, 2020
1 parent 3553835 commit f70a71e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/directives/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ export function handleTextDirective(el, output, expression) {
output = ''
}

if (el instanceof HTMLElement) {
el.innerText = output
} else {
el.textContent = output
}
el.textContent = output
}
6 changes: 3 additions & 3 deletions test/text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('x-text on init', async () => {

Alpine.start()

await wait(() => { expect(document.querySelector('span').innerText).toEqual('bar') })
await wait(() => { expect(document.querySelector('span').textContent).toEqual('bar') })
})

test('x-text on triggered update', async () => {
Expand All @@ -28,11 +28,11 @@ test('x-text on triggered update', async () => {

Alpine.start()

await wait(() => { expect(document.querySelector('span').innerText).toEqual('') })
await wait(() => { expect(document.querySelector('span').textContent).toEqual('') })

document.querySelector('button').click()

await wait(() => { expect(document.querySelector('span').innerText).toEqual('bar') })
await wait(() => { expect(document.querySelector('span').textContent).toEqual('bar') })
})

test('x-text on SVG elements', async () => {
Expand Down

0 comments on commit f70a71e

Please sign in to comment.