73
rated 0 times
[
74]
[
1]
/ answers: 1 / hits: 18634
/ 7 Years ago, wed, december 20, 2017, 12:00:00
When testing using jest I saw that the property innerText
is undefined while not in test it has the right value.
it('get text from div', () => {
const div = document.createElement('DIV')
div.innerHTML = '<br>a<br>b<br>c'
console.log('innerText', div.innerText) // undefined
console.log('textContent', div.textContent) // 'abc'
// expect(getTextFromDiv(div).length).toMatchSnapshot()
})
But when using the same code not in jest test, the innerText shows :
'a
b
c'
and textContent is 'abc'
.
Why innerText in jest is undefined and when it's not in a jest than the value is real?
This is the code where it works (not in jest):
const addTextInRichTextToPdf = (doc, text, offsetY) => {
const div = document.createElement('DIV')
div.innerHTML = '<br>a<br>b<br>c'
console.log('innerText', div.innerText) // print the real value
console.log('textContent', div.textContent) // 'abc'
...
More From » reactjs