Преглед изворни кода

test: check unexpected warnings

Evan You пре 9 година
родитељ
комит
00c137fb27
2 измењених фајлова са 18 додато и 1 уклоњено
  1. 17 0
      test/helpers/to-have-been-warned.js
  2. 1 1
      test/helpers/wait-for-update.js

+ 17 - 0
test/helpers/to-have-been-warned.js

@@ -5,6 +5,7 @@ if (typeof console === 'undefined') {
   }
 }
 
+let asserted
 function hasWarned (msg) {
   var count = console.error.calls.count()
   var args
@@ -23,11 +24,13 @@ function hasWarned (msg) {
 
 // define custom matcher for warnings
 beforeEach(() => {
+  asserted = []
   spyOn(console, 'error')
   jasmine.addMatchers({
     toHaveBeenWarned: () => {
       return {
         compare: msg => {
+          asserted = asserted.concat(msg)
           var warned = Array.isArray(msg)
             ? msg.some(hasWarned)
             : hasWarned(msg)
@@ -42,3 +45,17 @@ beforeEach(() => {
     }
   })
 })
+
+afterEach(done => {
+  const warned = msg => asserted.some(assertedMsg => msg.indexOf(assertedMsg) > -1)
+  let count = console.error.calls.count()
+  let args
+  while (count--) {
+    args = console.error.calls.argsFor(count)
+    if (!warned(args[0])) {
+      done.fail(`Unexpected console.error message: ${args[0]}`)
+      return
+    }
+  }
+  done()
+})

+ 1 - 1
test/helpers/wait-for-update.js

@@ -40,7 +40,7 @@ window.waitForUpdate = initialCb => {
 
   Vue.nextTick(() => {
     if (!queue.length || !queue[queue.length - 1].fail) {
-      console.warn('waitForUpdate chain is missing .then(done)')
+      throw new Error('waitForUpdate chain is missing .then(done)')
     }
     shift()
   })