8
0
Prechádzať zdrojové kódy

Added tests for the `CKEditorError.rethrowUnexpectedError()`.

Maciej Bukowski 6 rokov pred
rodič
commit
95be93a880

+ 27 - 0
packages/ckeditor5-utils/tests/ckeditorerror.js

@@ -4,6 +4,7 @@
  */
  */
 
 
 import { default as CKEditorError, DOCUMENTATION_URL } from '../src/ckeditorerror';
 import { default as CKEditorError, DOCUMENTATION_URL } from '../src/ckeditorerror';
+import { expectToThrowCKEditorError } from './_utils/utils';
 
 
 describe( 'CKEditorError', () => {
 describe( 'CKEditorError', () => {
 	it( 'inherits from Error', () => {
 	it( 'inherits from Error', () => {
@@ -88,4 +89,30 @@ describe( 'CKEditorError', () => {
 			expect( ( !!regularError.is && regularError.is( 'CKEditorError' ) ) ).to.be.false;
 			expect( ( !!regularError.is && regularError.is( 'CKEditorError' ) ) ).to.be.false;
 		} );
 		} );
 	} );
 	} );
+
+	describe( 'static rethrowUnexpectedError()', () => {
+		it( 'should rethrow the original CKEditorError as it is', () => {
+			const ckeditorError = new CKEditorError( 'foo', null );
+
+			expectToThrowCKEditorError( () => {
+				CKEditorError.rethrowUnexpectedError( ckeditorError, {} );
+			}, /foo/, null );
+		} );
+
+		it( 'should rethrow an unexpected error wrapped in CKEditorError', () => {
+			const error = new Error( 'foo' );
+			error.stack = 'bar';
+			const context = {};
+
+			expectToThrowCKEditorError( () => {
+				CKEditorError.rethrowUnexpectedError( error, context );
+			}, /unexpected-error/, context, {
+				originalError: {
+					message: 'foo',
+					stack: 'bar',
+					name: 'Error'
+				}
+			} );
+		} );
+	} );
 } );
 } );