Ver Fonte

Fixed syntax error. Added test.

Peter Minne há 4 anos atrás
pai
commit
33502ad127
2 ficheiros alterados com 21 adições e 1 exclusões
  1. 0 1
      src/directives/for.js
  2. 21 0
      test/for.spec.js

+ 0 - 1
src/directives/for.js

@@ -98,7 +98,6 @@ function evaluateItemsAndReturnEmptyIfXIfIsPresentAndFalseOnElement(component, e
     if (isNumeric(items)) {
         items = items > 0 ? Array.from(Array(items).keys(), i => i = 1) : []
     }
-    }
 
     return items
 }

+ 21 - 0
test/for.spec.js

@@ -556,3 +556,24 @@ test('x-for with an array of numbers', async () => {
         expect(document.querySelectorAll('span')[1].textContent).toEqual('3')
     })
 })
+
+test('x-for over range using i in x syntax with i <= 0', async () => {
+    document.body.innerHTML = `
+        <div x-data="{ count: 1 }">
+            <template x-for="i in count">
+                <span x-text="i"></span>
+            </template>
+            <button @click="count--"></button>
+        </div>
+    `
+
+    Alpine.start()
+
+    document.querySelector('button').click()
+
+    await wait(() => { expect(document.querySelectorAll('span').length).toEqual(0) })
+
+    document.querySelector('button').click()
+
+    await wait(() => { expect(document.querySelectorAll('span').length).toEqual(0) })
+})