index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // set some global Vue options
  2. var Vue = require('src')
  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.getWarnCount = function () {
  17. return _.warn.calls.count() + __.warn.calls.count()
  18. }
  19. function hasWarned (msg) {
  20. if (!_.warn.calls) {
  21. console.warn('make sure to call before tests.')
  22. }
  23. var count = _.warn.calls.count()
  24. var args
  25. while (count--) {
  26. args = _.warn.calls.argsFor(count)
  27. if (args.some(containsMsg)) {
  28. return true
  29. }
  30. }
  31. count = __.warn.calls.count()
  32. while (count--) {
  33. args = __.warn.calls.argsFor(count)
  34. if (args.some(containsMsg)) {
  35. return true
  36. }
  37. }
  38. function containsMsg (arg) {
  39. if (arg instanceof Error) throw arg
  40. return typeof arg === 'string' && arg.indexOf(msg) > -1
  41. }
  42. }
  43. // define custom matcher for warnings
  44. beforeEach(function () {
  45. spyOn(_, 'warn')
  46. spyOn(__, 'warn')
  47. jasmine.addMatchers({
  48. toHaveBeenWarned: function () {
  49. return {
  50. compare: function (msg) {
  51. var warned = Array.isArray(msg)
  52. ? msg.some(hasWarned)
  53. : hasWarned(msg)
  54. return {
  55. pass: warned,
  56. message: warned
  57. ? 'Expected message "' + msg + '" not to have been warned'
  58. : 'Expected message "' + msg + '" to have been warned'
  59. }
  60. }
  61. }
  62. }
  63. })
  64. })
  65. // shim process
  66. scope.process = {
  67. env: {
  68. NODE_ENV: 'development'
  69. }
  70. }
  71. // require all test files
  72. var testsContext = require.context('.', true, /_spec$/)
  73. testsContext.keys().forEach(testsContext)