Browse Source

use better warning assertions in tests

Evan You 11 years ago
parent
commit
3959b676e2

+ 1 - 1
src/directives/model/index.js

@@ -45,7 +45,7 @@ module.exports = {
     } else if (tag === 'TEXTAREA') {
       handler = handlers._default
     } else {
-      _.warn("v-model doesn't support element type: " + tag)
+      _.warn('v-model does not support element type: ' + tag)
       return
     }
     handler.bind.call(this)

+ 0 - 1
test/unit/runner.html

@@ -3,7 +3,6 @@
   <head>
     <meta charset="utf-8">
     <title>Vue.js unit tests</title>
-    <link rel="shortcut icon" type="image/png" href="lib/jasmine_favicon.png">
     <link rel="stylesheet" type="text/css" href="lib/jasmine.css">
     <script src="lib/jquery.js"></script>
     <script src="lib/jasmine.js"></script>

+ 2 - 2
test/unit/specs/api/data_spec.js

@@ -29,7 +29,7 @@ describe('Data API', function () {
     expect(vm.$get('c')).toBeUndefined()
     // invalid, should warn
     vm.$get('a(')
-    expect(_.warn).toHaveBeenCalled()
+    expect(hasWarned(_, 'Invalid expression')).toBe(true)
   })
 
   it('$set', function () {
@@ -46,7 +46,7 @@ describe('Data API', function () {
       // expression throws, the exp parser will catch the 
       // error and warn.
       vm.$set('c + d', 1)
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'Invalid setter function body')).toBe(true)
     } else {
       // otherwise it will throw when calling the setter.
       expect(function () {

+ 2 - 2
test/unit/specs/api/lifecycle_spec.js

@@ -57,7 +57,7 @@ if (_.inBrowser) {
       it('warn invalid selector', function () {
         var vm = new Vue()
         vm.$mount('#none-exist')
-        expect(_.warn).toHaveBeenCalled()
+        expect(hasWarned(_, 'Cannot find element')).toBe(true)
       })
 
       it('replace', function () {
@@ -145,7 +145,7 @@ if (_.inBrowser) {
           el: el
         })
         vm.$mount(el)
-        expect(_.warn).toHaveBeenCalled()
+        expect(hasWarned(_, '$mount() should be called only once')).toBe(true)
       })
 
     })

+ 1 - 1
test/unit/specs/batcher_spec.js

@@ -94,7 +94,7 @@ describe('Batcher', function () {
     batcher.push(job)
     nextTick(function () {
       expect(count).not.toBe(0)
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'infinite update loop')).toBe(true)
       done()
     })
   })

+ 1 - 1
test/unit/specs/compiler/transclude_spec.js

@@ -27,7 +27,7 @@ if (_.inBrowser) {
       options.template = '#non-existent-stuff'
       var res = transclude(el, options)
       expect(res).toBeUndefined()
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'Invalid template option')).toBe(true)
     })
 
     it('template replace', function () {

+ 1 - 1
test/unit/specs/directives/component_spec.js

@@ -379,7 +379,7 @@ if (_.inBrowser) {
       var vm = new Vue({
         el: el
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'already mounted instance')).toBe(true)
     })
 
   })

+ 7 - 3
test/unit/specs/directives/events_spec.js

@@ -34,7 +34,9 @@ if (_.inBrowser) {
         el: el,
         template: '<div v-events="test:test"></div>'
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_,
+        'should only be used on a child component ' +
+        'from the parent template')).toBe(true)
     })
 
     it('should warn when used on child component root', function () {
@@ -55,7 +57,9 @@ if (_.inBrowser) {
           }
         }
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_,
+        'should only be used on a child component ' +
+        'from the parent template')).toBe(true)
       expect(spy).not.toHaveBeenCalled()
     })
 
@@ -68,7 +72,7 @@ if (_.inBrowser) {
           test: {}
         }
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'expects a function value')).toBe(true)
     })
 
     it('should accept inline statement', function (done) {

+ 1 - 1
test/unit/specs/directives/if_spec.js

@@ -177,7 +177,7 @@ if (_.inBrowser) {
       var vm = new Vue({
         el: el
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'already mounted instance')).toBe(true)
     })
 
     it('v-if with content transclusion', function (done) {

+ 3 - 3
test/unit/specs/directives/model_spec.js

@@ -557,7 +557,7 @@ if (_.inBrowser) {
         el: el,
         template: '<div v-model="test"></div>'
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'does not support element type')).toBe(true)
     })
 
     it('warn invalid option value', function () {
@@ -566,7 +566,7 @@ if (_.inBrowser) {
         data: { a: 123 },
         template: '<select v-model="test" options="a"></select>'
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'Invalid options value')).toBe(true)
     })
 
     it('warn read-only filters', function () {
@@ -579,7 +579,7 @@ if (_.inBrowser) {
           }
         }
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'read-only filter')).toBe(true)
     })
 
     it('support jQuery change event', function (done) {

+ 1 - 1
test/unit/specs/directives/on_spec.js

@@ -77,7 +77,7 @@ if (_.inBrowser) {
         data: { test: 123 },
         template: '<a v-on="keyup:test"></a>'
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'expects a function value')).toBe(true)
     })
 
     it('iframe', function () {

+ 1 - 1
test/unit/specs/directives/ref_spec.js

@@ -115,7 +115,7 @@ if (_.inBrowser) {
         el: el,
         template: '<div v-ref="test"></div>'
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'should only be used on a component root element')).toBe(true)
     })
 
   })

+ 3 - 3
test/unit/specs/directives/repeat_spec.js

@@ -598,7 +598,7 @@ if (_.inBrowser) {
           test: {}
         }
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'Duplicate objects')).toBe(true)
     })
 
     it('warn duplicate trackby id', function () {
@@ -612,7 +612,7 @@ if (_.inBrowser) {
           test: {}
         }
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'Duplicate track-by key')).toBe(true)
     })
 
     it('warn v-if', function () {
@@ -623,7 +623,7 @@ if (_.inBrowser) {
           items: []
         }
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'Don\'t use v-if')).toBe(true)
     })
 
     it('repeat number', function () {

+ 3 - 3
test/unit/specs/directives/with_spec.js

@@ -122,7 +122,7 @@ if (_.inBrowser) {
         el: el,
         template: '<div v-with="test"></div>'
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'can only be used on instance root elements')).toBe(true)
     })
 
     it('no-parent warning', function () {
@@ -130,7 +130,7 @@ if (_.inBrowser) {
       var vm = new Vue({
         el: el
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'must be used on an instance with a parent')).toBe(true)
     })
 
     it('block instance with replace:true', function () {
@@ -179,7 +179,7 @@ if (_.inBrowser) {
           test: {}
         }
       })
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'cannot bind literal value as $data')).toBe(true)
     })
 
   })

+ 1 - 1
test/unit/specs/instance/events_spec.js

@@ -47,7 +47,7 @@ describe('Instance Events', function () {
       vm.$emit('test', 123)
       expect(spy).toHaveBeenCalledWith(123)
       vm.$emit('test2')
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'Unknown method')).toBe(true)
     })
 
   })

+ 3 - 3
test/unit/specs/parsers/expression_spec.js

@@ -276,21 +276,21 @@ describe('Expression Parser', function () {
     it('should warn on invalid expression', function () {
       expect(_.warn).not.toHaveBeenCalled()
       var res = expParser.parse('a--b"ffff')
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'Invalid expression')).toBe(true)
     })
 
     if (leftHandThrows()) {
       it('should warn on invalid left hand expression for setter', function () {
         expect(_.warn).not.toHaveBeenCalled()
         var res = expParser.parse('a+b', true)
-        expect(_.warn).toHaveBeenCalled()
+        expect(hasWarned(_, 'Invalid setter function body')).toBe(true)
       })
     }
 
     it('should warn if expression contains improper reserved keywords', function () {
       expect(_.warn).not.toHaveBeenCalled()
       var res = expParser.parse('break + 1')
-      expect(_.warn).toHaveBeenCalled()
+      expect(hasWarned(_, 'Avoid using reserved keywords')).toBe(true)
     })
   })
 })

+ 2 - 2
test/unit/specs/watcher_spec.js

@@ -388,13 +388,13 @@ describe('Watcher', function () {
 
   it('warn getter errors', function () {
     var watcher = new Watcher(vm, 'd.e + c', spy)
-    expect(_.warn).toHaveBeenCalled()
+    expect(hasWarned(_, 'Error when evaluating expression')).toBe(true)
   })
 
   it('warn setter errors', function () {
     var watcher = new Watcher(vm, 'a + b', spy)
     watcher.set(123)
-    expect(_.warn).toHaveBeenCalled()
+    expect(hasWarned(_, 'Error when evaluating setter')).toBe(true)
   })
 
 })