1
0
Эх сурвалжийг харах

Fixed syntax error. Added test.

Peter Minne 4 жил өмнө
parent
commit
33502ad127

+ 0 - 1
src/directives/for.js

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