Kaynağa Gözat

Added the `Watchdog#_now()` method.

Maciej Bukowski 6 yıl önce
ebeveyn
işleme
d6136cfbca
1 değiştirilmiş dosya ile 9 ekleme ve 1 silme
  1. 9 1
      packages/ckeditor5-watchdog/src/watchdog.js

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

@@ -65,6 +65,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}
 		 * @see module:watchdog/watchdog~WatchdogConfig
@@ -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 } );