瀏覽代碼

Proper cleaning after engine debugging utilities testing.

Szymon Kupś 8 年之前
父節點
當前提交
551a89c97f

+ 7 - 9
packages/ckeditor5-engine/src/dev-utils/enableenginedebug.js

@@ -52,7 +52,7 @@ import clone from '@ckeditor/ckeditor5-utils/src/lib/lodash/clone';
 
 class Sandbox {
 	constructor() {
-		this._stubs = new Set();
+		this._restores = [];
 	}
 
 	create( object, methodName, fakeMethod ) {
@@ -60,23 +60,21 @@ class Sandbox {
 
 		object[ methodName ] = fakeMethod;
 
-		fakeMethod.restore = function restore() {
+		this._restores.unshift( () => {
 			if ( originalMethod ) {
-				Object.defineProperty( object, methodName, originalMethod );
+				object[ methodName ] = originalMethod;
 			} else {
 				delete object[ methodName ];
 			}
-		};
-
-		this._stubs.add( object[ methodName ] );
+		} );
 	}
 
 	restore() {
-		for ( const stub of this._stubs.values() ) {
-			stub.restore();
+		for ( const restore of this._restores ) {
+			restore();
 		}
 
-		this._stubs.clear();
+		this._restores = [];
 	}
 }
 

+ 8 - 4
packages/ckeditor5-engine/tests/dev-utils/enableenginedebug.js

@@ -48,11 +48,11 @@ testUtils.createSinonSandbox();
 
 /* global document */
 
-after( () => {
-	disableEngineDebug();
-} );
-
 describe( 'enableEngineDebug', () => {
+	afterEach( () => {
+		disableEngineDebug();
+	} );
+
 	it( 'should return plugin class', () => {
 		const result = enableEngineDebug();
 
@@ -86,6 +86,10 @@ describe( 'debug tools', () => {
 		DebugPlugin = enableEngineDebug( { log, error } );
 	} );
 
+	after( () => {
+		disableEngineDebug();
+	} );
+
 	afterEach( () => {
 		log.reset();
 	} );