Răsfoiți Sursa

Add isCKEditorError() static method.

Maksymilian Barnaś 9 ani în urmă
părinte
comite
a1f58fae39

+ 10 - 0
packages/ckeditor5-utils/src/ckeditorerror.js

@@ -46,4 +46,14 @@ export default class CKEditorError extends Error {
 		 */
 		this.data = data;
 	}
+
+	/**
+	 * Checks if error is an instance of CKEditorError class.
+	 *
+	 * @param {Object} error Object to check.
+	 * @returns {Boolean}
+	 */
+	static isCKEditorError( error ) {
+		return error instanceof CKEditorError;
+	}
 }

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

@@ -51,4 +51,14 @@ describe( 'CKEditorError', () => {
 		expect( error ).to.have.property( 'message', 'foo {"bar":"a","bom":{"x":1},"bim":10}' );
 		expect( error ).to.have.property( 'data', data );
 	} );
+
+	describe( 'isCKEditorError', () => {
+		it( 'checks if error is an instance of CKEditorError', () => {
+			let ckeditorError = new CKEditorError( 'foo' );
+			let regularError = new Error( 'foo' );
+
+			expect( CKEditorError.isCKEditorError( ckeditorError ) ).to.be.true;
+			expect( CKEditorError.isCKEditorError( regularError ) ).to.be.false;
+		} );
+	} );
 } );