Преглед на файлове

test for simple directive

Evan You преди 12 години
родител
ревизия
c133e4a9c1
променени са 3 файла, в които са добавени 38 реда и са изтрити 9 реда
  1. 8 5
      test/functional/fixtures/simple-dir.html
  2. 10 4
      test/functional/specs/expression.js
  3. 20 0
      test/functional/specs/simple-dir.js

+ 8 - 5
test/functional/fixtures/simple-dir.html

@@ -3,28 +3,31 @@
     <head>
         <title></title>
         <meta charset="utf-8">
+        <script src="bind.js"></script>
         <script src="../../../dist/seed.js"></script>
     </head>
     <body>
-        <div id="hi" sd-test sd-test2></div>
+        <div id="hi" sd-test sd-test2>
+        </div>
+        <p class="one"></p>
+        <p class="two"></p>
         <script>
             var a = new Seed({
                 el: '#hi',
                 directives: {
                     test: {
                         bind: function () {
-                            console.log('bind')
+                            document.querySelector('.one').textContent = 'bind'
                         },
                         unbind: function () {
-                            console.log('unbind')
+                            document.querySelector('.one').textContent = 'unbind'
                         }
                     },
                     test2: function () {
-                        console.log('test2 bind')
+                        document.querySelector('.two').textContent = 'bind'
                     }
                 }
             })
-            a.$destroy()
         </script>
     </body>
 </html>

+ 10 - 4
test/functional/specs/expression.js

@@ -1,4 +1,4 @@
-casper.test.begin('Expression', 8, function (test) {
+casper.test.begin('Expression', 9, function (test) {
     
     casper
     .start('./fixtures/expression.html', function () {
@@ -10,14 +10,20 @@ casper.test.begin('Expression', 8, function (test) {
         test.assertField('three', 'Hi')
         test.assertField('four', 'Ho')
 
-        // lazy
+        // setting value
+        this.evaluate(function () {
+            normal.one = 'Hola'
+        })
+        test.assertSelectorHasText('#normal p', 'Hola World!')
+
+        // lazy input
         this.fill('#form', {
             three: 'three',
             four: 'four'
         })
         test.assertSelectorHasText('#lazy p', 'three four!')
 
-        // normal
+        // normal input
         this.evaluate(function () {
             var one = document.getElementById('one')
             var e = document.createEvent('MouseEvent')
@@ -26,7 +32,7 @@ casper.test.begin('Expression', 8, function (test) {
             one.dispatchEvent(e)
         })
         test.assertSelectorHasText('#normal p', 'Bye World!')
-        
+
     })
     .run(function () {
         test.done()

+ 20 - 0
test/functional/specs/simple-dir.js

@@ -0,0 +1,20 @@
+casper.test.begin('Simple Directive', 3, function (test) {
+    
+    casper
+    .start('./fixtures/simple-dir.html', function () {
+
+        test.assertSelectorHasText('.one', 'bind', 'object definition bind')
+        test.assertSelectorHasText('.two', 'bind', 'function definition bind')
+
+        this.evaluate(function () {
+            a.$destroy()
+        })
+
+        test.assertSelectorHasText('.one', 'unbind', 'object definition unbind')
+
+    })
+    .run(function () {
+        test.done()
+    })
+
+})