github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/themes/wind/static/libs/vue-1.0.24/test/unit/specs/index.js (about)

     1  // set some global Vue options
     2  var Vue = require('src')
     3  Vue.options.replace = false
     4  Vue.config.silent = true
     5  
     6  /**
     7   * Because Vue's internal modules reference the warn function
     8   * from different modules (some from util and some from debug),
     9   * we need to normalize the warn check into a few global
    10   * utility functions.
    11   */
    12  
    13  var _ = require('src/util')
    14  var __ = require('src/util/debug')
    15  var scope = typeof window === 'undefined'
    16    ? global
    17    : window
    18  
    19  scope.getWarnCount = function () {
    20    return _.warn.calls.count() + __.warn.calls.count()
    21  }
    22  
    23  function hasWarned (msg) {
    24    var count = _.warn.calls.count()
    25    var args
    26    while (count--) {
    27      args = _.warn.calls.argsFor(count)
    28      if (args.some(containsMsg)) {
    29        return true
    30      }
    31    }
    32  
    33    count = __.warn.calls.count()
    34    while (count--) {
    35      args = __.warn.calls.argsFor(count)
    36      if (args.some(containsMsg)) {
    37        return true
    38      }
    39    }
    40  
    41    function containsMsg (arg) {
    42      if (arg instanceof Error) throw arg
    43      return typeof arg === 'string' && arg.indexOf(msg) > -1
    44    }
    45  }
    46  
    47  // define custom matcher for warnings
    48  beforeEach(function () {
    49    spyOn(_, 'warn')
    50    spyOn(__, 'warn')
    51    jasmine.addMatchers({
    52      toHaveBeenWarned: function () {
    53        return {
    54          compare: function (msg) {
    55            var warned = Array.isArray(msg)
    56              ? msg.some(hasWarned)
    57              : hasWarned(msg)
    58            return {
    59              pass: warned,
    60              message: warned
    61                ? 'Expected message "' + msg + '" not to have been warned'
    62                : 'Expected message "' + msg + '" to have been warned'
    63            }
    64          }
    65        }
    66      }
    67    })
    68  })
    69  
    70  // shim process
    71  scope.process = {
    72    env: {
    73      NODE_ENV: 'development'
    74    }
    75  }
    76  
    77  // require all test files
    78  var testsContext = require.context('.', true, /_spec$/)
    79  testsContext.keys().forEach(testsContext)