Browse Source

Add "if" directive test

Caleb Porzio 5 years ago
parent
commit
eb3473c03d
1 changed files with 26 additions and 0 deletions
  1. 26 0
      test/if.spec.js

+ 26 - 0
test/if.spec.js

@@ -0,0 +1,26 @@
+import Alpine from 'alpinejs'
+import { wait } from '@testing-library/dom'
+
+global.MutationObserver = class {
+    observe() {}
+}
+
+test('x-if', async () => {
+    document.body.innerHTML = `
+        <div x-data="{ show: false }">
+            <button x-on:click="show = ! show"></button>
+
+            <template x-if="show">
+                <p></p>
+            </template>
+        </div>
+    `
+
+    Alpine.start()
+
+    expect(document.querySelector('p')).toBeFalsy()
+
+    document.querySelector('button').click()
+
+    await wait(() => { expect(document.querySelector('p')).toBeTruthy() })
+})