2
0

debug_spec.js 1.3 KB

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