debug_spec.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var _ = require('../../../../src/util')
  2. var config = require('../../../../src/config')
  3. var infoPrefix = '[Vue info]: '
  4. var warnPrefix = '[Vue warn]: '
  5. config.silent = true
  6. if (typeof console !== 'undefined') {
  7. describe('Util - Debug', function () {
  8. beforeEach(function () {
  9. spyOn(console, 'log')
  10. spyOn(console, 'warn')
  11. if (console.trace) {
  12. spyOn(console, 'trace')
  13. }
  14. })
  15. it('log when debug is true', function () {
  16. config.debug = true
  17. _.log('hello')
  18. expect(console.log).toHaveBeenCalledWith(infoPrefix + 'hello')
  19. })
  20. it('not log when debug is false', function () {
  21. config.debug = false
  22. _.log('bye')
  23. expect(console.log.calls.count()).toBe(0)
  24. })
  25. it('warn when silent is false', function () {
  26. config.silent = false
  27. _.warn('oops')
  28. expect(console.warn).toHaveBeenCalledWith(warnPrefix + 'oops')
  29. })
  30. it('not warn when silent is ture', function () {
  31. config.silent = true
  32. _.warn('oops')
  33. expect(console.warn.calls.count()).toBe(0)
  34. })
  35. if (console.trace) {
  36. it('trace when not silent and debugging', function () {
  37. config.debug = true
  38. config.silent = false
  39. _.warn('haha')
  40. expect(console.trace).toHaveBeenCalled()
  41. config.debug = false
  42. config.silent = true
  43. })
  44. }
  45. })
  46. }