Console.spec.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* eslint-disable no-console */
  2. /* eslint-disable no-restricted-globals */
  3. /* eslint-disable no-global-assign */
  4. import {
  5. log,
  6. warn,
  7. info,
  8. error
  9. } from 'handsontable/helpers/console';
  10. describe('Console', () => {
  11. describe('log', () => {
  12. it('should call function `console.log` with all arguments', () => {
  13. console.log = jasmine.createSpy('log');
  14. log('a', 'b', 'c');
  15. expect(console.log).toHaveBeenCalledWith('a', 'b', 'c');
  16. });
  17. it('should not throw Exception when `console` is not exposed', () => {
  18. const cachedConsole = console;
  19. console = undefined;
  20. expect(() => {
  21. log('a', 'b', 'c');
  22. }).not.toThrow();
  23. console = cachedConsole;
  24. });
  25. });
  26. describe('warn', () => {
  27. it('should call function `console.warn` with all arguments', () => {
  28. console.warn = jasmine.createSpy('warn');
  29. warn('a', 'b', 'c');
  30. expect(console.warn).toHaveBeenCalledWith('a', 'b', 'c');
  31. });
  32. it('should not throw Exception when `console` is not exposed', () => {
  33. const cachedConsole = console;
  34. console = undefined;
  35. expect(() => {
  36. warn('a', 'b', 'c');
  37. }).not.toThrow();
  38. console = cachedConsole;
  39. });
  40. });
  41. describe('info', () => {
  42. it('should call function `console.info` with all arguments', () => {
  43. console.info = jasmine.createSpy('info');
  44. info('a', 'b', 'c');
  45. expect(console.info).toHaveBeenCalledWith('a', 'b', 'c');
  46. });
  47. it('should not throw Exception when `console` is not exposed', () => {
  48. const cachedConsole = console;
  49. console = undefined;
  50. expect(() => {
  51. info('a', 'b', 'c');
  52. }).not.toThrow();
  53. console = cachedConsole;
  54. });
  55. });
  56. describe('error', () => {
  57. it('should call function `console.error` with all arguments', () => {
  58. console.error = jasmine.createSpy('error');
  59. error('a', 'b', 'c');
  60. expect(console.error).toHaveBeenCalledWith('a', 'b', 'c');
  61. });
  62. it('should not throw Exception when `console` is not exposed', () => {
  63. const cachedConsole = console;
  64. console = undefined;
  65. expect(() => {
  66. error('a', 'b', 'c');
  67. }).not.toThrow();
  68. console = cachedConsole;
  69. });
  70. });
  71. });