Skip to content

Commit

Permalink
add test for _x_isInit
Browse files Browse the repository at this point in the history
  • Loading branch information
Matsa59 committed Jan 30, 2024
1 parent 76ca794 commit 4051b97
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/cypress/integration/mutation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,36 @@ test('can pause and queue mutations for later resuming/flushing',
}
)

test('add and move element are been initialized',
html`
<div x-data="{
foo: 0,
bar: 0,
test() {
container = document.createElement('div')
this.$root.appendChild(container)
alpineElement = document.createElement('span')
alpineElement.setAttribute('x-data', '{init() {this.bar++}}')
alpineElement.setAttribute('x-init', 'foo++')
container.appendChild(alpineElement)
container.removeChild(alpineElement)
container.appendChild(alpineElement)
}
}">
<span id="one" x-text="foo"></span>
<span id="two" x-text="bar"></span>
<button @click="test">Test</button>
</div>
`,
({ get }) => {
get('span#one').should(haveText('0'))
get('span#two').should(haveText('0'))
get('button').click()
get('span#one').should(haveText('1'))
get('span#two').should(haveText('1'))
}
)

test('does not initialise components twice when contained in multiple mutations',
html`
<div x-data="{
Expand Down

0 comments on commit 4051b97

Please sign in to comment.