index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // set some global Vue options
  2. var Vue = require('../../../src/index')
  3. Vue.options.replace = false
  4. Vue.config.silent = true
  5. /**
  6. * Because Vue's internal modules reference the warn function
  7. * from different modules (some from util and some from debug),
  8. * we need to normalize the warn check into a few global
  9. * utility functions.
  10. */
  11. var _ = require('../../../src/util')
  12. var __ = require('../../../src/util/debug')
  13. var scope = typeof window === 'undefined'
  14. ? global
  15. : window
  16. scope.spyWarns = function () {
  17. spyOn(_, 'warn')
  18. spyOn(__, 'warn')
  19. }
  20. scope.getWarnCount = function () {
  21. return _.warn.calls.count() + __.warn.calls.count()
  22. }
  23. scope.hasWarned = function (msg, silent) {
  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. count = __.warn.calls.count()
  33. while (count--) {
  34. args = __.warn.calls.argsFor(count)
  35. if (args.some(containsMsg)) {
  36. return true
  37. }
  38. }
  39. if (!silent) {
  40. console.warn('[test] "' + msg + '" was never warned.')
  41. }
  42. function containsMsg (arg) {
  43. if (arg instanceof Error) throw arg
  44. return typeof arg === 'string' && arg.indexOf(msg) > -1
  45. }
  46. }
  47. scope.process = {
  48. env: {
  49. NODE_ENV: 'development'
  50. }
  51. }
  52. // require all test files
  53. var testsContext = require.context('.', true, /_spec$/)
  54. testsContext.keys().forEach(testsContext)