Преглед на файлове

Made `assertCKEditorError` accepting strings and regexps as messages.

Maciej Bukowski преди 6 години
родител
ревизия
d137282891
променени са 1 файла, в които са добавени 7 реда и са изтрити 4 реда
  1. 7 4
      packages/ckeditor5-utils/tests/_utils/utils.js

+ 7 - 4
packages/ckeditor5-utils/tests/_utils/utils.js

@@ -92,7 +92,7 @@ export function assertBinding( observable, stateBefore, data, stateAfter ) {
  * have common props (So the watchdog will be able to find the correct editor instance and restart it).
  *
  * @param {Function} fn Tested function that should throw a `CKEditorError`.
- * @param {RegExp} message  Expected message of the error.
+ * @param {RegExp|String} message Expected message of the error.
  * @param {*} editorThatShouldBeFindableFromContext An editor instance that should be findable from the error context.
  * @param {Object} [data] Error data.
  */
@@ -116,14 +116,17 @@ export function expectToThrowCKEditorError( fn, message, editorThatShouldBeFinda
  * find the correct editor instance and restart it).
  *
  * @param {module:utils/ckeditorerror~CKEditorError} err The tested error.
- * @param {RegExp} message Expected message of the error.
+ * @param {RegExp|String} message Expected message of the error.
  * @param {*} [editorThatShouldBeFindableFromContext] An editor instance that should be findable from the error context.
  * @param {Object} [data] Error data.
  */
 export function assertCKEditorError( err, message, editorThatShouldBeFindableFromContext, data ) {
-	expect( err ).to.be.instanceOf( CKEditorError );
-	expect( message ).to.be.a( 'regexp', `Error message should be a string. Got ${ typeof message }.` );
+	if ( typeof message === 'string' ) {
+		message = new RegExp( message );
+	}
 
+	expect( message ).to.be.a( 'regexp', 'Error message should be a string or a regexp.' );
+	expect( err ).to.be.instanceOf( CKEditorError );
 	expect( err.message ).to.match( message, 'Error message does not match the provided one.' );
 
 	// TODO: The `editorThatShouldBeFindableFromContext` is optional but should be required in the future.