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

tests(watchers): basic cypress

Ryan Chandler 4 жил өмнө
parent
commit
fdbed3f085

+ 22 - 0
tests/cypress/fixtures/watchers/init.html

@@ -0,0 +1,22 @@
+<html>
+    <head>
+        <script src="/dist/spruce.umd.js"></script>
+        <script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.js"></script>
+    </head>
+    <body>
+        <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>
+
+        <script>
+            Spruce.store('persisted', {
+                foo: 'bar',
+                bar: 'boo'
+            }, true)
+
+            Spruce.watch('persisted.foo', () => {
+                Spruce.store('persisted').bar = 'bop'
+            })
+        </script>
+    </body>
+</html>

+ 15 - 0
tests/cypress/integration/watchers.spec.js

@@ -0,0 +1,15 @@
+/* global describe, it, cy */
+
+describe('watchers', () => {
+    it('can watch for changes on a store', () => {
+        cy.visit('/tests/cypress/fixtures/watchers/init.html')
+
+        cy.get('p').should('have.text', 'bar')
+        cy.get('span').should('have.text', 'boo')
+
+        cy.get('button').click()
+
+        cy.get('p').should('have.text', 'car')
+        cy.get('span').should('have.text', 'bop')
+    })
+})