Pārlūkot izejas kodu

tests: array watchers

Ryan Chandler 4 gadi atpakaļ
vecāks
revīzija
342423525c

+ 27 - 2
tests/cypress/fixtures/watchers/init.html

@@ -4,17 +4,42 @@
     </head>
     </head>
     <body>
     <body>
         <p x-data x-text="$store.persisted.foo"></p>
         <p x-data x-text="$store.persisted.foo"></p>
-        <button x-data @click="$store.persisted.foo = 'car'"></button>
-        <span x-data x-text="$store.persisted.bar"></span>
+        <button data-change-foo x-data @click="$store.persisted.foo = 'car'"></button>
+        <span data-bar x-data x-text="$store.persisted.bar"></span>
+
+        <div x-data>
+            <ul>
+                <template x-for="todo in $store.todo.todos">
+                    <li data-todo-item x-text="todo"></li>
+                </template>
+            </ul>
+            <button data-add-todo @click="$store.todo.add('Example')">Add Todo</button>
+            <span data-todo-label x-text="$store.todoLabel.test"></span>
+        </div>
 
 
         <script src="/dist/spruce.umd.js"></script>
         <script src="/dist/spruce.umd.js"></script>
 
 
         <script>
         <script>
+            Spruce.store('todo', {
+                todos: [],
+                add(todo) {
+                    this.todos.push(todo)
+                }
+            })
+
+            Spruce.store('todoLabel', {
+                test: 'Yes!'
+            })
+
             Spruce.store('persisted', {
             Spruce.store('persisted', {
                 foo: 'bar',
                 foo: 'bar',
                 bar: 'boo'
                 bar: 'boo'
             }, true)
             }, true)
 
 
+            Spruce.watch('todo.todos', () => {
+                Spruce.store('todoLabel').test = 'Yay!'
+            })
+
             Spruce.watch('persisted.foo', () => {
             Spruce.watch('persisted.foo', () => {
                 Spruce.store('persisted').bar = 'bop'
                 Spruce.store('persisted').bar = 'bop'
             })
             })

+ 11 - 3
tests/cypress/integration/watchers.spec.js

@@ -5,11 +5,19 @@ describe('watchers', () => {
         cy.visit('/tests/cypress/fixtures/watchers/init.html')
         cy.visit('/tests/cypress/fixtures/watchers/init.html')
 
 
         cy.get('p').should('have.text', 'bar')
         cy.get('p').should('have.text', 'bar')
-        cy.get('span').should('have.text', 'boo')
+        cy.get('[data-bar]').should('have.text', 'boo')
 
 
-        cy.get('button').click()
+        cy.get('[data-change-foo]').click()
 
 
         cy.get('p').should('have.text', 'car')
         cy.get('p').should('have.text', 'car')
-        cy.get('span').should('have.text', 'bop')
+        cy.get('[data-bar]').should('have.text', 'bop')
+
+        cy.get('[data-todo-item]').should('have.length', 0)
+        cy.get('[data-todo-label]').should('have.text', 'Yes!')
+
+        cy.get('[data-add-todo]').click()
+
+        cy.get('[data-todo-item]').should('have.length', 1)
+        cy.get('[data-todo-label]').should('have.text', 'Yay!')
     })
     })
 })
 })