index.js 1.8 KB

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