Просмотр исходного кода

unit test pass for async batch / functional test expression pass

Evan You 12 лет назад
Родитель
Сommit
789adffa2f
4 измененных файлов с 74 добавлено и 49 удалено
  1. 6 1
      src/batch.js
  2. 1 0
      src/config.js
  3. 37 27
      test/functional/specs/expression.js
  4. 30 21
      test/unit/specs/api.js

+ 6 - 1
src/batch.js

@@ -1,9 +1,14 @@
-var utils = require('./utils'),
+var config = require('./config'),
+    utils = require('./utils'),
     queue, has, waiting
 
 reset()
 
 exports.queue = function (binding, method) {
+    if (!config.async) {
+        binding['_' + method]()
+        return
+    }
     if (!has[binding.id]) {
         queue.push({
             binding: binding,

+ 1 - 0
src/config.js

@@ -1,6 +1,7 @@
 module.exports = {
 
     prefix      : 'v',
+    async       : true,
     debug       : false,
     silent      : false,
     enterClass  : 'v-enter',

+ 37 - 27
test/functional/specs/expression.js

@@ -3,59 +3,69 @@
 casper.test.begin('Expression', 19, function (test) {
     
     casper
-    .start('./fixtures/expression.html', function () {
-
+    .start('./fixtures/expression.html')
+    .then(function () {
         test.assertSelectorHasText('#normal p', 'Hello World!')
         test.assertSelectorHasText('#lazy p', 'Hi Ho!')
         test.assertField('one', 'Hello')
         test.assertField('two', 'World')
         test.assertField('three', 'Hi')
         test.assertField('four', 'Ho')
-
+    })
+    .thenEvaluate(function () {
         // setting value
-        this.evaluate(function () {
-            normal.one = 'Hola'
-        })
+        normal.one = 'Hola'
+    })
+    .then(function () {
         test.assertSelectorHasText('#normal p', 'Hola World!')
-        test.assertField('one', 'Hola')
-
+        test.assertField('one', 'Hola')  
+    })
+    .thenEvaluate(function () {
         // setting nested value
-        this.evaluate(function () {
-            normal.two.three = 'Casper'
-        })
+        normal.two.three = 'Casper'
+    })
+    .then(function () {
         test.assertSelectorHasText('#normal p', 'Hola Casper!')
-        test.assertField('two', 'Casper')
-
+        test.assertField('two', 'Casper')  
+    })
+    .then(function () {
         // lazy input
         this.fill('#form', {
             three: 'three',
             four: 'four'
         })
+    })
+    .then(function () {
         test.assertSelectorHasText('#lazy p', 'three four!')
-
+    })
+    .then(function () {
         // normal input
         this.sendKeys('#one', 'Bye')
+    })
+    .then(function () {
         test.assertSelectorHasText('#normal p', 'Bye Casper!')
-
-        // v-on with expression
-        this.click('#normal button')
+    })
+    // v-on with expression
+    .thenClick('#normal button', function () {
         test.assertField('one', 'clicked')
         test.assertSelectorHasText('#normal p', 'clicked Casper!')
-
-        // v-on with expression
-        this.click('#lazy button')
+    })
+    // v-on with expression
+    .thenClick('#lazy button', function () {
         test.assertField('four', 'clicked')
         test.assertSelectorHasText('#lazy p', 'three clicked!')
-
-        // conditional expression
-        // e.g. ok ? yesMSg : noMsg
-        // make sure all three are captured as dependency
+    })
+    // conditional expression
+    // e.g. ok ? yesMSg : noMsg
+    // make sure all three are captured as dependency
+    .then(function () {
         test.assertSelectorHasText('#conditional p', 'YES')
-        this.click('#conditional .toggle')
+    })
+    .thenClick('#conditional .toggle', function () {
         test.assertSelectorHasText('#conditional p', 'NO')
-        this.click('#conditional .change')
+    })
+    .thenClick('#conditional .change', function () {
         test.assertSelectorHasText('#conditional p', 'Nah')
-
     })
     .run(function () {
         test.done()

+ 30 - 21
test/unit/specs/api.js

@@ -201,7 +201,7 @@ describe('UNIT: API', function () {
             assert.strictEqual(Vue.transition(testId), transition)
         })
 
-        it('should work with v-transition', function () {
+        it('should work with v-transition', function (done) {
 
             var enterCalled = false,
                 leaveCalled = false
@@ -230,14 +230,17 @@ describe('UNIT: API', function () {
             document.body.appendChild(t.$el)
             
             t.show = true
-            assert.ok(enterCalled)
-            assert.strictEqual(t.$el.style.display, '')
-
-            t.show = false
-            assert.ok(leaveCalled)
-            assert.strictEqual(t.$el.style.display, 'none')
-
-            t.$destroy()
+            setTimeout(function () {
+                assert.ok(enterCalled)
+                assert.strictEqual(t.$el.style.display, '')
+                t.show = false
+                setTimeout(function () {
+                    assert.ok(leaveCalled)
+                    assert.strictEqual(t.$el.style.display, 'none')
+                    t.$destroy()
+                    done()
+                }, 0)
+            }, 0)
         })
 
     })
@@ -488,7 +491,7 @@ describe('UNIT: API', function () {
 
             describe('directives', function () {
                 
-                it('should allow the VM to use private directives', function () {
+                it('should allow the VM to use private directives', function (done) {
                     var Test = Vue.extend({
                         directives: {
                             test: function (value) {
@@ -506,7 +509,10 @@ describe('UNIT: API', function () {
                     })
                     assert.strictEqual(t.$el.innerHTML, 'YES')
                     t.ok = false
-                    assert.strictEqual(t.$el.innerHTML, 'NO')
+                    setTimeout(function () {
+                        assert.strictEqual(t.$el.innerHTML, 'NO')
+                        done()
+                    }, 0)
                 })
 
             })
@@ -599,7 +605,7 @@ describe('UNIT: API', function () {
 
             describe('transitions', function () {
                 
-                it('should get called during transitions', function () {
+                it('should get called during transitions', function (done) {
                     
                     var enterCalled = false,
                         leaveCalled = false
@@ -627,16 +633,19 @@ describe('UNIT: API', function () {
                     })
 
                     document.body.appendChild(t.$el)
-                    
-                    t.show = true
-                    assert.ok(enterCalled)
-                    assert.strictEqual(t.$el.style.display, '')
-
-                    t.show = false
-                    assert.ok(leaveCalled)
-                    assert.strictEqual(t.$el.style.display, 'none')
 
-                    t.$destroy()
+                    t.show = true
+                    setTimeout(function () {
+                        assert.ok(enterCalled)
+                        assert.strictEqual(t.$el.style.display, '')
+                        t.show = false
+                        setTimeout(function () {
+                            assert.ok(leaveCalled)
+                            assert.strictEqual(t.$el.style.display, 'none')
+                            t.$destroy()
+                            done()
+                        }, 0)
+                    }, 0)
 
                 })