Browse Source

use custom matcher for warning tests

Evan You 10 years ago
parent
commit
208678b8a4

+ 1 - 1
package.json

@@ -56,7 +56,7 @@
     "eslint-plugin-promise": "^1.0.8",
     "eslint-plugin-standard": "^1.3.2",
     "istanbul-instrumenter-loader": "^0.1.3",
-    "jasmine-core": "^2.3.4",
+    "jasmine-core": "^2.4.1",
     "karma": "^0.13.8",
     "karma-chrome-launcher": "^0.2.0",
     "karma-coverage": "^0.5.0",

+ 3 - 4
test/unit/specs/api/data_spec.js

@@ -5,7 +5,6 @@ var nextTick = _.nextTick
 describe('Data API', function () {
   var vm
   beforeEach(function () {
-    spyWarns()
     vm = new Vue({
       data: {
         a: 1,
@@ -33,7 +32,7 @@ describe('Data API', function () {
     expect(vm.$get('c')).toBeUndefined()
     // invalid, should warn
     vm.$get('a(')
-    expect(hasWarned('Invalid expression')).toBe(true)
+    expect('Invalid expression').toHaveBeenWarned()
   })
 
   it('$set', function () {
@@ -45,12 +44,12 @@ describe('Data API', function () {
     vm.$set('c.d', 2)
     expect(vm.c.d).toBe(2)
     // warn against setting unexisting
-    expect(hasWarned('Consider pre-initializing')).toBe(true)
+    expect('Consider pre-initializing').toHaveBeenWarned()
   })
 
   it('$set invalid', function () {
     vm.$set('c + d', 1)
-    expect(hasWarned('Invalid setter expression')).toBe(true)
+    expect('Invalid setter expression').toHaveBeenWarned()
   })
 
   it('$delete', function () {

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

@@ -9,7 +9,6 @@ describe('Lifecycle API', function () {
       el.textContent = '{{test}}'
       frag = document.createDocumentFragment()
       frag.appendChild(el)
-      spyWarns()
     })
 
     it('normal', function () {
@@ -53,7 +52,7 @@ describe('Lifecycle API', function () {
     it('warn invalid selector', function () {
       var vm = new Vue()
       vm.$mount('#none-exist')
-      expect(hasWarned('Cannot find element')).toBe(true)
+      expect('Cannot find element').toHaveBeenWarned()
     })
 
     it('replace', function () {
@@ -141,7 +140,7 @@ describe('Lifecycle API', function () {
         el: el
       })
       vm.$mount(el)
-      expect(hasWarned('$mount() should be called only once')).toBe(true)
+      expect('$mount() should be called only once').toHaveBeenWarned()
     })
   })
 

+ 1 - 2
test/unit/specs/async_component_spec.js

@@ -6,7 +6,6 @@ describe('Async components', function () {
   beforeEach(function () {
     el = document.createElement('div')
     document.body.appendChild(el)
-    spyWarns()
   })
 
   afterEach(function () {
@@ -199,7 +198,7 @@ describe('Async components', function () {
         }
       }
     })
-    expect(hasWarned('Reason: nooooo')).toBe(true)
+    expect('Reason: nooooo').toHaveBeenWarned()
   })
 
   it('v-for', function (done) {

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

@@ -6,7 +6,6 @@ describe('Batcher', function () {
   var spy
   beforeEach(function () {
     spy = jasmine.createSpy('batcher')
-    spyWarns()
   })
 
   it('pushWatcher', function (done) {
@@ -93,7 +92,7 @@ describe('Batcher', function () {
     batcher.pushWatcher(job)
     nextTick(function () {
       expect(count).toBe(config._maxUpdateCount + 1)
-      expect(hasWarned('infinite update loop')).toBe(true)
+      expect('infinite update loop').toHaveBeenWarned()
       done()
     })
   })

+ 7 - 8
test/unit/specs/compiler/compile_spec.js

@@ -46,7 +46,6 @@ describe('Compile', function () {
     spyOn(vm, '_bindDir').and.callThrough()
     spyOn(vm, '$eval').and.callThrough()
     spyOn(vm, '$interpolate').and.callThrough()
-    spyWarns()
   })
 
   it('normal directives', function () {
@@ -327,7 +326,7 @@ describe('Compile', function () {
     expect(prop.parentPath).toBe('a')
     expect(prop.mode).toBe(bindingModes.TWO_WAY)
     // two way warn
-    expect(hasWarned('non-settable parent path')).toBe(true)
+    expect('non-settable parent path').toHaveBeenWarned()
     // literal with filter
     args = vm._bindDir.calls.argsFor(3)
     prop = args[0].prop
@@ -585,7 +584,7 @@ describe('Compile', function () {
       }
     })
     expect(el.innerHTML).toBe('<div></div>')
-    expect(hasWarned('attribute interpolation is not allowed in Vue.js directives')).toBe(true)
+    expect('attribute interpolation is not allowed in Vue.js directives').toHaveBeenWarned()
   })
 
   it('attribute interpolation: warn mixed usage with v-bind', function () {
@@ -596,7 +595,7 @@ describe('Compile', function () {
         a: 'hi'
       }
     })
-    expect(hasWarned('Do not mix mustache interpolation and v-bind')).toBe(true)
+    expect('Do not mix mustache interpolation and v-bind').toHaveBeenWarned()
   })
 
   it('warn directives on fragment instances', function () {
@@ -612,10 +611,10 @@ describe('Compile', function () {
       }
     })
     expect(getWarnCount()).toBe(1)
-    expect(
-      hasWarned('Attributes "id", "class" are ignored on component <test>', true) ||
-      hasWarned('Attributes "class", "id" are ignored on component <test>')
-    ).toBe(true)
+    expect([
+      'Attributes "id", "class" are ignored on component <test>',
+      'Attributes "class", "id" are ignored on component <test>'
+    ]).toHaveBeenWarned()
   })
 
   it('should compile component container directives using correct context', function () {

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

@@ -7,7 +7,6 @@ describe('Transclude', function () {
   beforeEach(function () {
     el = document.createElement('div')
     options = _.extend({}, Vue.options)
-    spyWarns()
   })
 
   it('normal', function () {
@@ -26,7 +25,7 @@ describe('Transclude', function () {
     options.template = '#non-existent-stuff'
     var res = transclude(el, options)
     expect(res).toBeUndefined()
-    expect(hasWarned('Invalid template option')).toBe(true)
+    expect('Invalid template option').toHaveBeenWarned()
   })
 
   it('template replace', function () {

+ 1 - 2
test/unit/specs/directives/element/slot_spec.js

@@ -4,7 +4,6 @@ var nextTick = Vue.nextTick
 describe('Slot Distribution', function () {
   var el, vm, options
   beforeEach(function () {
-    spyWarns()
     el = document.createElement('div')
     options = {
       el: el,
@@ -140,7 +139,7 @@ describe('Slot Distribution', function () {
       theName: 'two'
     }
     mount()
-    expect(hasWarned('slot names cannot be dynamic')).toBe(true)
+    expect('slot names cannot be dynamic').toHaveBeenWarned()
   })
 
   it('content should be dynamic and compiled in parent scope', function (done) {

+ 2 - 3
test/unit/specs/directives/internal/component_spec.js

@@ -6,7 +6,6 @@ describe('Component', function () {
   beforeEach(function () {
     el = document.createElement('div')
     document.body.appendChild(el)
-    spyWarns()
   })
 
   afterEach(function () {
@@ -519,7 +518,7 @@ describe('Component', function () {
     new Vue({
       el: el
     })
-    expect(hasWarned('cannot mount component "test" on already mounted element')).toBe(true)
+    expect('cannot mount component "test" on already mounted element').toHaveBeenWarned()
   })
 
   it('not found component should not throw', function () {
@@ -539,6 +538,6 @@ describe('Component', function () {
         'hello-world': {}
       }
     })
-    expect(hasWarned('did you mean <hello-world>?')).toBe(true)
+    expect('did you mean <hello-world>?').toHaveBeenWarned()
   })
 })

+ 27 - 28
test/unit/specs/directives/internal/prop_spec.js

@@ -4,7 +4,6 @@ describe('prop', function () {
   var el
   beforeEach(function () {
     el = document.createElement('div')
-    spyWarns()
   })
 
   it('one way binding', function (done) {
@@ -150,7 +149,7 @@ describe('prop', function () {
         }
       }
     })
-    expect(hasWarned('Cannot bind two-way prop with non-settable parent path')).toBe(true)
+    expect('Cannot bind two-way prop with non-settable parent path').toHaveBeenWarned()
     expect(el.innerHTML).toBe('<test>BB</test>')
     vm.b = 'BB'
     Vue.nextTick(function () {
@@ -181,7 +180,7 @@ describe('prop', function () {
         }
       }
     })
-    expect(hasWarned('expects a two-way binding type')).toBe(true)
+    expect('expects a two-way binding type').toHaveBeenWarned()
   })
 
   it('warn $data as prop', function () {
@@ -197,7 +196,7 @@ describe('prop', function () {
         }
       }
     })
-    expect(hasWarned('Do not use $data as prop')).toBe(true)
+    expect('Do not use $data as prop').toHaveBeenWarned()
   })
 
   it('warn invalid keys', function () {
@@ -210,14 +209,14 @@ describe('prop', function () {
         }
       }
     })
-    expect(hasWarned('Invalid prop key')).toBe(true)
+    expect('Invalid prop key').toHaveBeenWarned()
   })
 
   it('warn props with no el option', function () {
     new Vue({
       props: ['a']
     })
-    expect(hasWarned('Props will not be compiled if no `el`')).toBe(true)
+    expect('Props will not be compiled if no `el`').toHaveBeenWarned()
   })
 
   it('warn object/array default values', function () {
@@ -234,7 +233,7 @@ describe('prop', function () {
         }
       }
     })
-    expect(hasWarned('Use a factory function to return the default value')).toBe(true)
+    expect('Use a factory function to return the default value').toHaveBeenWarned()
     expect(getWarnCount()).toBe(2)
   })
 
@@ -319,42 +318,42 @@ describe('prop', function () {
       makeInstance('hello', String)
       expect(getWarnCount()).toBe(0)
       makeInstance(123, String)
-      expect(hasWarned('Expected String')).toBe(true)
+      expect('Expected String').toHaveBeenWarned()
     })
 
     it('number', function () {
       makeInstance(123, Number)
       expect(getWarnCount()).toBe(0)
       makeInstance('123', Number)
-      expect(hasWarned('Expected Number')).toBe(true)
+      expect('Expected Number').toHaveBeenWarned()
     })
 
     it('boolean', function () {
       makeInstance(true, Boolean)
       expect(getWarnCount()).toBe(0)
       makeInstance('123', Boolean)
-      expect(hasWarned('Expected Boolean')).toBe(true)
+      expect('Expected Boolean').toHaveBeenWarned()
     })
 
     it('function', function () {
       makeInstance(function () {}, Function)
       expect(getWarnCount()).toBe(0)
       makeInstance(123, Function)
-      expect(hasWarned('Expected Function')).toBe(true)
+      expect('Expected Function').toHaveBeenWarned()
     })
 
     it('object', function () {
       makeInstance({}, Object)
       expect(getWarnCount()).toBe(0)
       makeInstance([], Object)
-      expect(hasWarned('Expected Object')).toBe(true)
+      expect('Expected Object').toHaveBeenWarned()
     })
 
     it('array', function () {
       makeInstance([], Array)
       expect(getWarnCount()).toBe(0)
       makeInstance({}, Array)
-      expect(hasWarned('Expected Array')).toBe(true)
+      expect('Expected Array').toHaveBeenWarned()
     })
 
     it('custom constructor', function () {
@@ -362,7 +361,7 @@ describe('prop', function () {
       makeInstance(new Class(), Class)
       expect(getWarnCount()).toBe(0)
       makeInstance({}, Class)
-      expect(hasWarned('Expected custom type')).toBe(true)
+      expect('Expected custom type').toHaveBeenWarned()
     })
 
     it('custom validator', function () {
@@ -373,7 +372,7 @@ describe('prop', function () {
       makeInstance(123, null, function (v) {
         return v === 234
       })
-      expect(hasWarned('custom validator check failed')).toBe(true)
+      expect('custom validator check failed').toHaveBeenWarned()
     })
 
     it('type check + custom validator', function () {
@@ -384,11 +383,11 @@ describe('prop', function () {
       makeInstance(123, Number, function (v) {
         return v === 234
       })
-      expect(hasWarned('custom validator check failed')).toBe(true)
+      expect('custom validator check failed').toHaveBeenWarned()
       makeInstance(123, String, function (v) {
         return v === 123
       })
-      expect(hasWarned('Expected String')).toBe(true)
+      expect('Expected String').toHaveBeenWarned()
     })
 
     it('type check + coerce', function () {
@@ -414,7 +413,7 @@ describe('prop', function () {
           }
         }
       })
-      expect(hasWarned('Missing required prop')).toBe(true)
+      expect('Missing required prop').toHaveBeenWarned()
     })
 
     it('optional with type + null/undefined', function () {
@@ -427,10 +426,10 @@ describe('prop', function () {
     it('required with type + null/undefined', function () {
       makeInstance(undefined, String, null, null, true)
       expect(getWarnCount()).toBe(1)
-      expect(hasWarned('Expected String')).toBe(true)
+      expect('Expected String').toHaveBeenWarned()
       makeInstance(null, Boolean, null, null, true)
       expect(getWarnCount()).toBe(2)
-      expect(hasWarned('Expected Boolean')).toBe(true)
+      expect('Expected Boolean').toHaveBeenWarned()
     })
   })
 
@@ -457,8 +456,8 @@ describe('prop', function () {
         }
       }
     })
-    expect(hasWarned('Missing required prop')).toBe(true)
-    expect(hasWarned('Expected Number')).toBe(true)
+    expect('Missing required prop').toHaveBeenWarned()
+    expect('Expected Number').toHaveBeenWarned()
     expect(el.textContent).toBe('AAA')
   })
 
@@ -487,8 +486,8 @@ describe('prop', function () {
         }
       }
     })
-    expect(hasWarned('Missing required prop')).toBe(true)
-    expect(hasWarned('Expected Number')).toBe(true)
+    expect('Missing required prop').toHaveBeenWarned()
+    expect('Expected Number').toHaveBeenWarned()
     expect(el.textContent).toBe('AAA')
   })
 
@@ -591,7 +590,7 @@ describe('prop', function () {
         comp: Comp
       }
     })
-    expect(hasWarned('already defined as a prop')).toBe(true)
+    expect('already defined as a prop').toHaveBeenWarned()
   })
 
   it('should not warn data fields already defined as a prop if it is from instantiation call', function () {
@@ -677,9 +676,9 @@ describe('prop', function () {
       }
     })
     expect(getWarnCount()).toBe(3)
-    expect(hasWarned('did you mean `prop-a`')).toBe(true)
-    expect(hasWarned('did you mean `prop-b`')).toBe(true)
-    expect(hasWarned('did you mean `prop-c`')).toBe(true)
+    expect('did you mean `prop-a`').toHaveBeenWarned()
+    expect('did you mean `prop-b`').toHaveBeenWarned()
+    expect('did you mean `prop-c`').toHaveBeenWarned()
   })
 
   it('should use default for undefined values', function () {

+ 0 - 1
test/unit/specs/directives/public/el_spec.js

@@ -5,7 +5,6 @@ describe('el', function () {
   var el
   beforeEach(function () {
     el = document.createElement('div')
-    spyWarns()
   })
 
   it('normal', function (done) {

+ 5 - 6
test/unit/specs/directives/public/for/for_spec.js

@@ -5,7 +5,6 @@ describe('v-for', function () {
   var el
   beforeEach(function () {
     el = document.createElement('div')
-    spyWarns()
   })
 
   it('objects', function (done) {
@@ -551,7 +550,7 @@ describe('v-for', function () {
       el: el,
       template: '<div v-for="items"></div>'
     })
-    expect(hasWarned('Alias is required in v-for')).toBe(true)
+    expect('Alias is required in v-for').toHaveBeenWarned()
   })
 
   it('warn duplicate objects', function () {
@@ -563,7 +562,7 @@ describe('v-for', function () {
         items: [obj, obj]
       }
     })
-    expect(hasWarned('Duplicate value')).toBe(true)
+    expect('Duplicate value').toHaveBeenWarned()
   })
 
   it('warn duplicate objects on diff', function (done) {
@@ -578,7 +577,7 @@ describe('v-for', function () {
     expect(getWarnCount()).toBe(0)
     vm.items.push(obj)
     _.nextTick(function () {
-      expect(hasWarned('Duplicate value')).toBe(true)
+      expect('Duplicate value').toHaveBeenWarned()
       done()
     })
   })
@@ -591,7 +590,7 @@ describe('v-for', function () {
         items: [{id: 1}, {id: 1}]
       }
     })
-    expect(hasWarned('Duplicate value')).toBe(true)
+    expect('Duplicate value').toHaveBeenWarned()
   })
 
   it('key val syntax with object', function (done) {
@@ -725,7 +724,7 @@ describe('v-for', function () {
       }
     })
     trigger(vm.$el.querySelector('input'), 'input')
-    expect(hasWarned('It seems you are using two-way binding')).toBe(true)
+    expect('It seems you are using two-way binding').toHaveBeenWarned()
   })
 
   it('nested track by', function (done) {

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

@@ -5,7 +5,6 @@ describe('v-if', function () {
   var el
   beforeEach(function () {
     el = document.createElement('div')
-    spyWarns()
   })
 
   it('normal', function (done) {
@@ -171,7 +170,7 @@ describe('v-if', function () {
     new Vue({
       el: el
     })
-    expect(hasWarned('cannot be used on an instance root element')).toBe(true)
+    expect('cannot be used on an instance root element').toHaveBeenWarned()
   })
 
   it('call attach/detach for transcluded components', function (done) {

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

@@ -39,7 +39,6 @@ describe('v-model', function () {
     el = document.createElement('div')
     el.style.display = 'none'
     document.body.appendChild(el)
-    spyWarns()
   })
 
   it('radio buttons', function (done) {
@@ -639,7 +638,7 @@ describe('v-model', function () {
       el: el,
       template: '<div v-model="test"></div>'
     })
-    expect(hasWarned('does not support element type')).toBe(true)
+    expect('does not support element type').toHaveBeenWarned()
   })
 
   it('warn read-only filters', function () {
@@ -652,7 +651,7 @@ describe('v-model', function () {
         }
       }
     })
-    expect(hasWarned('read-only filter')).toBe(true)
+    expect('read-only filter').toHaveBeenWarned()
   })
 
   it('support jQuery change event', function (done) {

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

@@ -13,7 +13,6 @@ describe('v-on', function () {
   var el
   beforeEach(function () {
     el = document.createElement('div')
-    spyWarns()
   })
 
   it('methods', function () {
@@ -274,7 +273,7 @@ describe('v-on', function () {
       data: { test: 123 },
       template: '<a v-on:keyup="test"></a>'
     })
-    expect(hasWarned('expects a function value')).toBe(true)
+    expect('expects a function value').toHaveBeenWarned()
   })
 
   it('iframe', function () {

+ 0 - 4
test/unit/specs/directives/public/pre_spec.js

@@ -1,10 +1,6 @@
 var Vue = require('src')
 
 describe('v-pre', function () {
-  beforeEach(function () {
-    spyWarns()
-  })
-
   it('should work', function () {
     var vm = new Vue({
       el: document.createElement('div'),

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

@@ -5,7 +5,6 @@ describe('ref', function () {
   var el
   beforeEach(function () {
     el = document.createElement('div')
-    spyWarns()
   })
 
   var components = {
@@ -141,6 +140,6 @@ describe('ref', function () {
       el: el,
       template: '<div v-ref:test></div>'
     })
-    expect(hasWarned('must be used on a child component')).toBe(true)
+    expect('must be used on a child component').toHaveBeenWarned()
   })
 })

+ 3 - 7
test/unit/specs/global_api_spec.js

@@ -4,10 +4,6 @@ var config = require('src/config')
 var transition = require('src/transition')
 
 describe('Global API', function () {
-  beforeEach(function () {
-    spyWarns()
-  })
-
   it('exposed utilities', function () {
     expect(Vue.util).toBe(_)
     expect(Vue.nextTick).toBe(_.nextTick)
@@ -46,11 +42,11 @@ describe('Global API', function () {
 
   it('extend warn invalid names', function () {
     Vue.extend({ name: '123' })
-    expect(hasWarned('Invalid component name: "123"')).toBe(true)
+    expect('Invalid component name: "123"').toHaveBeenWarned()
     Vue.extend({ name: '_fesf' })
-    expect(hasWarned('Invalid component name: "_fesf"')).toBe(true)
+    expect('Invalid component name: "_fesf"').toHaveBeenWarned()
     Vue.extend({ name: 'Some App' })
-    expect(hasWarned('Invalid component name: "Some App"')).toBe(true)
+    expect('Invalid component name: "Some App"').toHaveBeenWarned()
   })
 
   it('use', function () {

+ 33 - 11
test/unit/specs/index.js

@@ -16,18 +16,13 @@ var scope = typeof window === 'undefined'
   ? global
   : window
 
-scope.spyWarns = function () {
-  spyOn(_, 'warn')
-  spyOn(__, 'warn')
-}
-
 scope.getWarnCount = function () {
   return _.warn.calls.count() + __.warn.calls.count()
 }
 
-scope.hasWarned = function (msg, silent) {
+function hasWarned (msg) {
   if (!_.warn.calls) {
-    console.warn('make sure to call spyWarns() before tests.')
+    console.warn('make sure to call before tests.')
   }
   var count = _.warn.calls.count()
   var args
@@ -46,16 +41,43 @@ scope.hasWarned = function (msg, silent) {
     }
   }
 
-  if (!silent) {
-    console.warn('[test] "' + msg + '" was never warned.')
-  }
-
   function containsMsg (arg) {
     if (arg instanceof Error) throw arg
     return typeof arg === 'string' && arg.indexOf(msg) > -1
   }
 }
 
+// define custom matcher for warnings
+beforeEach(function () {
+  spyOn(_, 'warn')
+  spyOn(__, 'warn')
+  jasmine.addMatchers({
+    toHaveBeenWarned: function () {
+      return {
+        compare: function (msg) {
+          var warned = Array.isArray(msg)
+            ? msg.some(hasWarned)
+            : hasWarned(msg)
+          return {
+            pass: warned,
+            message: warned
+              ? 'Expected message "' + msg + '" not to have been warned'
+              : 'Expected message "' + msg + '" to have been warned'
+          }
+        }
+      }
+    }
+  })
+})
+
+describe('custom matcher', function () {
+  it('should work', function () {
+    _.warn('lol')
+    expect('lol').toHaveBeenWarned()
+  })
+})
+
+// shim process
 scope.process = {
   env: {
     NODE_ENV: 'development'

+ 2 - 5
test/unit/specs/instance/events_spec.js

@@ -6,7 +6,6 @@ describe('Instance Events', function () {
   beforeEach(function () {
     spy = jasmine.createSpy()
     spy2 = jasmine.createSpy()
-    spyWarns()
   })
 
   describe('option events', function () {
@@ -45,7 +44,7 @@ describe('Instance Events', function () {
       vm.$emit('test', 123)
       expect(spy).toHaveBeenCalledWith(123)
       vm.$emit('test2')
-      expect(hasWarned('Unknown method')).toBe(true)
+      expect('Unknown method').toHaveBeenWarned()
     })
   })
 
@@ -239,9 +238,7 @@ describe('Instance Events', function () {
           comp: {}
         }
       })
-      expect(hasWarned(
-        'v-on:test="onThat" on component <comp> expects a function value'
-      )).toBe(true)
+      expect('v-on:test="onThat" on component <comp> expects a function value').toHaveBeenWarned()
     })
 
     it('passing $arguments', function () {

+ 1 - 5
test/unit/specs/instance/misc_spec.js

@@ -23,10 +23,6 @@ describe('misc', function () {
       }
     })
 
-    beforeEach(function () {
-      spyWarns()
-    })
-
     it('read', function () {
       var filters = [
         { name: 'read', args: [{dynamic: false, value: 'AAA'}] },
@@ -46,7 +42,7 @@ describe('misc', function () {
 
     it('warn not found', function () {
       vm._applyFilters('what', null, [{name: 'wtf'}])
-      expect(hasWarned('Failed to resolve filter')).toBe(true)
+      expect('Failed to resolve filter').toHaveBeenWarned()
     })
   })
 })

+ 1 - 5
test/unit/specs/misc_spec.js

@@ -3,10 +3,6 @@ var Vue = require('src')
 var _ = Vue.util
 
 describe('Misc', function () {
-  beforeEach(function () {
-    spyWarns()
-  })
-
   it('should handle directive.bind() altering its childNode structure', function () {
     var vm = new Vue({
       el: document.createElement('div'),
@@ -318,7 +314,7 @@ describe('Misc', function () {
       el: document.createElement('div'),
       template: '<custom-stuff></custom-stuff>'
     })
-    expect(hasWarned('Unknown custom element')).toBe(true)
+    expect('Unknown custom element').toHaveBeenWarned()
   })
 
   it('prefer bound attributes over static attributes', function (done) {

+ 0 - 4
test/unit/specs/observer/observer_spec.js

@@ -6,10 +6,6 @@ var Dep = require('src/observer/dep')
 var _ = require('src/util')
 
 describe('Observer', function () {
-  beforeEach(function () {
-    spyWarns()
-  })
-
   it('create on non-observables', function () {
     // skip primitive value
     var ob = observe(1)

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

@@ -298,26 +298,22 @@ describe('Expression Parser', function () {
   }
 
   describe('invalid expression', function () {
-    beforeEach(function () {
-      spyWarns()
-    })
-
     it('should warn on invalid expression', function () {
       expect(getWarnCount()).toBe(0)
       expParser.parseExpression('a--b"ffff')
-      expect(hasWarned('Invalid expression')).toBe(true)
+      expect('Invalid expression').toHaveBeenWarned()
     })
 
     it('should warn on invalid setter expression', function () {
       expect(getWarnCount()).toBe(0)
       expParser.parseExpression('a+b', true)
-      expect(hasWarned('Invalid setter expression')).toBe(true)
+      expect('Invalid setter expression').toHaveBeenWarned()
     })
 
     it('should warn if expression contains improper reserved keywords', function () {
       expect(getWarnCount()).toBe(0)
       expParser.parseExpression('break + 1')
-      expect(hasWarned('Avoid using reserved keywords')).toBe(true)
+      expect('Avoid using reserved keywords').toHaveBeenWarned()
     })
   })
 })

+ 2 - 1
test/unit/specs/util/debug_spec.js

@@ -5,7 +5,6 @@ var warnPrefix = '[Vue warn]: '
 if (typeof console !== 'undefined') {
   describe('Util - Debug', function () {
     beforeEach(function () {
-      spyOn(console, 'log')
       spyOn(console, 'warn')
       if (console.trace) {
         spyOn(console, 'trace')
@@ -14,12 +13,14 @@ if (typeof console !== 'undefined') {
 
     it('warn when silent is false', function () {
       config.silent = false
+      _.warn.and.callThrough()
       _.warn('oops')
       expect(console.warn).toHaveBeenCalledWith(warnPrefix + 'oops')
     })
 
     it('not warn when silent is ture', function () {
       config.silent = true
+      _.warn.and.callThrough()
       _.warn('oops')
       expect(console.warn).not.toHaveBeenCalled()
     })

+ 4 - 8
test/unit/specs/util/options_spec.js

@@ -4,10 +4,6 @@ var merge = _.mergeOptions
 var resolveAsset = _.resolveAsset
 
 describe('Util - Option merging', function () {
-  beforeEach(function () {
-    spyWarns()
-  })
-
   it('default strat', function () {
     // child undefined
     var res = merge({replace: true}, {}).replace
@@ -159,7 +155,7 @@ describe('Util - Option merging', function () {
         a: { template: 'hi' }
       }
     })
-    expect(hasWarned('Do not use built-in or reserved HTML elements as component id: a')).toBe(true)
+    expect('Do not use built-in or reserved HTML elements as component id: a').toHaveBeenWarned()
     merge({
       components: null
     }, {
@@ -167,7 +163,7 @@ describe('Util - Option merging', function () {
         slot: { template: 'hi' }
       }
     })
-    expect(hasWarned('Do not use built-in or reserved HTML elements as component id: slot')).toBe(true)
+    expect('Do not use built-in or reserved HTML elements as component id: slot').toHaveBeenWarned()
   })
 
   it('should ignore non-function el & data in class merge', function () {
@@ -335,7 +331,7 @@ describe('Util - Option merging', function () {
       components: [{}]
     }
     merge(a, b)
-    expect(hasWarned('must provide a "name" or "id" field')).toBe(true)
+    expect('must provide a "name" or "id" field').toHaveBeenWarned()
   })
 
   it('warn Array async component without id', function () {
@@ -348,7 +344,7 @@ describe('Util - Option merging', function () {
       components: [function () {}]
     }
     merge(a, b)
-    expect(hasWarned('must provide a "name" or "id" field')).toBe(true)
+    expect('must provide a "name" or "id" field').toHaveBeenWarned()
   })
 })
 

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

@@ -20,7 +20,6 @@ describe('Watcher', function () {
       }
     })
     spy = jasmine.createSpy('watcher')
-    spyWarns()
   })
 
   it('simple path', function (done) {
@@ -364,12 +363,12 @@ describe('Watcher', function () {
 
   it('warn getter errors', function () {
     new Watcher(vm, 'd.e + c', spy)
-    expect(hasWarned('Error when evaluating expression')).toBe(true)
+    expect('Error when evaluating expression').toHaveBeenWarned()
   })
 
   it('warn setter errors', function () {
     var watcher = new Watcher(vm, 'a + b', spy)
     watcher.set(123)
-    expect(hasWarned('Error when evaluating setter')).toBe(true)
+    expect('Error when evaluating setter').toHaveBeenWarned()
   })
 })