ckeditorerror.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import CKEditorError from 'ckeditor5/utils/ckeditorerror.js';
  6. describe( 'CKEditorError', () => {
  7. it( 'inherits from Error', () => {
  8. let error = new CKEditorError( 'foo' );
  9. expect( error ).to.be.an.instanceOf( Error );
  10. expect( error ).to.be.an.instanceOf( CKEditorError );
  11. } );
  12. it( 'sets the name', () => {
  13. let error = new CKEditorError( 'foo' );
  14. expect( error ).to.have.property( 'name', 'CKEditorError' );
  15. } );
  16. it( 'sets the message', () => {
  17. let error = new CKEditorError( 'foo' );
  18. expect( error ).to.have.property( 'message', 'foo' );
  19. expect( error.data ).to.be.undefined;
  20. } );
  21. it( 'sets the message and data', () => {
  22. let data = { bar: 1 };
  23. let error = new CKEditorError( 'foo', data );
  24. expect( error ).to.have.property( 'message', 'foo {"bar":1}' );
  25. expect( error ).to.have.property( 'data', data );
  26. } );
  27. it( 'appends stringified data to the message', () => {
  28. class Foo {
  29. constructor() {
  30. this.x = 1;
  31. }
  32. }
  33. let data = {
  34. bar: 'a',
  35. bom: new Foo(),
  36. bim: 10
  37. };
  38. let error = new CKEditorError( 'foo', data );
  39. expect( error ).to.have.property( 'message', 'foo {"bar":"a","bom":{"x":1},"bim":10}' );
  40. expect( error ).to.have.property( 'data', data );
  41. } );
  42. describe( 'isCKEditorError', () => {
  43. it( 'checks if error is an instance of CKEditorError', () => {
  44. let ckeditorError = new CKEditorError( 'foo' );
  45. let regularError = new Error( 'foo' );
  46. expect( CKEditorError.isCKEditorError( ckeditorError ) ).to.be.true;
  47. expect( CKEditorError.isCKEditorError( regularError ) ).to.be.false;
  48. } );
  49. } );
  50. } );