debug_spec.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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).not.toHaveBeenCalled()
  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).not.toHaveBeenCalled()
  34. })
  35. })
  36. }