Explorar o código

Add failing test

Simone Todaro %!s(int64=5) %!d(string=hai) anos
pai
achega
9b80e9a4c0
Modificáronse 1 ficheiros con 23 adicións e 0 borrados
  1. 23 0
      test/watch.spec.js

+ 23 - 0
test/watch.spec.js

@@ -52,3 +52,26 @@ test('$watch nested properties', async () => {
         expect(document.querySelector('h2').innerText).toEqual('law')
     })
 })
+
+test('$watch arrays', async () => {
+    document.body.innerHTML = `
+        <div x-data="{ foo: ['one'], bob: 'lob' }" x-init="$watch('foo', value => { bob = 'baz' })">
+            <h1 x-text="foo"></h1>
+            <h2 x-text="bob"></h2>
+
+            <button x-on:click="foo.push('two')"></button>
+        </div>
+    `
+
+    Alpine.start()
+
+    expect(document.querySelector('h1').innerText).toEqual(['one'])
+    expect(document.querySelector('h2').innerText).toEqual('lob')
+
+    document.querySelector('button').click()
+
+    await wait(() => {
+        expect(document.querySelector('h1').innerText).toEqual(['one','two'])
+        expect(document.querySelector('h2').innerText).toEqual('baz')
+    })
+})