debug_spec.js 1.0 KB

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