8
0

log.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console */
  6. import log from '../src/log';
  7. import { DOCUMENTATION_URL } from '../src/ckeditorerror';
  8. describe( 'log', () => {
  9. let spy;
  10. beforeEach( () => {
  11. if ( spy ) {
  12. spy.restore();
  13. }
  14. } );
  15. describe( 'warn()', () => {
  16. it( 'logs the message to the console using console.warn()', () => {
  17. spy = sinon.stub( console, 'warn' );
  18. const data = { bar: 1 };
  19. log.warn( 'foo', data );
  20. sinon.assert.calledOnce( spy );
  21. sinon.assert.calledWith( spy, 'foo', data );
  22. log.warn( 'bar' );
  23. sinon.assert.calledTwice( spy );
  24. sinon.assert.calledWith( spy, 'bar' );
  25. } );
  26. it( 'contains a link which leads to the documentation', () => {
  27. spy = sinon.stub( console, 'warn' );
  28. log.warn( 'model-schema-no-item: Specified item cannot be found.' );
  29. const logMessage = 'model-schema-no-item: Specified item cannot be found. ' +
  30. `Read more: ${ DOCUMENTATION_URL }#model-schema-no-item\n`;
  31. sinon.assert.calledOnce( spy );
  32. sinon.assert.calledWith( spy, logMessage );
  33. } );
  34. } );
  35. describe( 'error()', () => {
  36. it( 'logs the message to the console using console.error()', () => {
  37. spy = sinon.stub( console, 'error' );
  38. const data = { bar: 1 };
  39. log.error( 'foo', data );
  40. sinon.assert.calledOnce( spy );
  41. sinon.assert.calledWith( spy, 'foo', data );
  42. log.error( 'bar' );
  43. sinon.assert.calledTwice( spy );
  44. sinon.assert.calledWith( spy, 'bar' );
  45. } );
  46. it( 'contains a link which leads to the documentation', () => {
  47. spy = sinon.stub( console, 'error' );
  48. log.error( 'model-schema-no-item: Specified item cannot be found.' );
  49. const logMessage = 'model-schema-no-item: Specified item cannot be found. ' +
  50. `Read more: ${ DOCUMENTATION_URL }#model-schema-no-item\n`;
  51. sinon.assert.calledOnce( spy );
  52. sinon.assert.calledWith( spy, logMessage );
  53. } );
  54. } );
  55. } );