8
0
فهرست منبع

Added the `Watchdog#_now()` method.

Maciej Bukowski 6 سال پیش
والد
کامیت
d6136cfbca
1فایلهای تغییر یافته به همراه9 افزوده شده و 1 حذف شده
  1. 9 1
      packages/ckeditor5-watchdog/src/watchdog.js

+ 9 - 1
packages/ckeditor5-watchdog/src/watchdog.js

@@ -64,6 +64,14 @@ export default class Watchdog {
 		 */
 		this._crashNumberLimit = typeof config.crashNumberLimit === 'number' ? config.crashNumberLimit : 3;
 
+		/**
+		 * Returns the result of `Date.now()` call. It can be overridden in tests to mock time as the popular
+		 * approaches like `sinon.useFakeTimers()` does not work well with error handling.
+		 *
+		 * @protected
+		 */
+		this._now = () => Date.now();
+
 		/**
 		 * @private
 		 * @type {Number}
@@ -311,7 +319,7 @@ export default class Watchdog {
 				source: evt.source,
 				lineno: evt.lineno,
 				colno: evt.colno,
-				date: Date.now()
+				date: this._now()
 			} );
 
 			this.fire( 'error', { error: evt.error } );