Skip to content

Commit

Permalink
Add tests for text expression
Browse files Browse the repository at this point in the history
  • Loading branch information
kachurun committed Oct 21, 2024
1 parent 161cb1c commit a2042b8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/expressions/text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,34 @@ describe('text specs', () => {

expect(p.textContent).to.be.equal('0')
})

it('Text can restore value upon update (https://github.com/riot/riot/issues/3023)', () => {
const target = document.createElement('div')
const el = template('<p expr0><----></p>', [
{
selector: '[expr0]',
expressions: [
{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: (scope) => scope.val,
},
],
},
]).mount(target, { val: 'hello' })

const p = target.querySelector('p')

// normal update
expect(p.textContent).to.be.equal('hello')
el.update({ val: 'world' })

expect(p.textContent).to.be.equal('world')

p.childNodes[0].data = 'Boo!'

// update to same value but after value was changed from the outside
el.update({ val: 'world' })
expect(p.textContent).to.be.equal('world')
})
})

0 comments on commit a2042b8

Please sign in to comment.