浏览代码

add test for _x_isInit

Matsa 1 年之前
父节点
当前提交
4051b97f57
共有 1 个文件被更改,包括 30 次插入0 次删除
  1. 30 0
      tests/cypress/integration/mutation.spec.js

+ 30 - 0
tests/cypress/integration/mutation.spec.js

@@ -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="{