Skip to content

Commit

Permalink
Merge branch 'master' into fix-$watch-and-support-nested-properties
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Mar 19, 2020
2 parents 20398b8 + 47084f9 commit 4c7e506
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/constructor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,51 @@ test('auto-initialize new elements added to a component', async () => {
await wait(() => { expect(document.querySelector('#target span').innerText).toEqual(1) })
})

test('Alpine mutations don\'t trigger (like x-if and x-for) MutationObserver', async () => {
var runObservers = []
var evaluations = 0

global.MutationObserver = class {
constructor(callback) { runObservers.push(callback) }
observe() {}
}
window.bob = () => {
evaluations++
return 'lob'
}

document.body.innerHTML = `
<div x-data="{ foo: 'bar' }" id="component">
<template x-if="foo === 'baz'">
<span x-text="bob()"></span>
</template>
<button @click="foo = 'baz'"></button>
</div>
`

Alpine.start()

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

// Wait out the rendering tick.
await new Promise(resolve => setTimeout(resolve, 1))

// Run both queud mutations.
runObservers[0]([
{ target: document.querySelector('#component'), addedNodes: [
document.querySelector('#component span'),
] }
])
runObservers[1]([
{ target: document.querySelector('#component'), addedNodes: [
document.querySelector('#component span'),
] }
])

expect(evaluations).toEqual(1)
})

test('auto-detect x-data property changes at run-time', async () => {
var runObservers = []

Expand Down

0 comments on commit 4c7e506

Please sign in to comment.