浏览代码

Tests: DomEmitterMixin tests should not pollute DOM with obsolete elements in document.body.

Aleksander Nowodzinski 8 年之前
父节点
当前提交
3c19d3d23d
共有 1 个文件被更改,包括 26 次插入14 次删除
  1. 26 14
      packages/ckeditor5-utils/tests/dom/emittermixin.js

+ 26 - 14
packages/ckeditor5-utils/tests/dom/emittermixin.js

@@ -65,17 +65,23 @@ describe( 'DomEmitterMixin', () => {
 		} );
 
 		// #187
-		it( 'should work for DOM Nodes belonging to another window', () => {
+		it( 'should work for DOM Nodes belonging to another window', done => {
 			const spy = testUtils.sinon.spy();
 			const iframe = document.createElement( 'iframe' );
 
-			document.body.appendChild( iframe );
-			const iframeNode = iframe.contentWindow.document.createElement( 'div' );
+			iframe.addEventListener( 'load', () => {
+				const iframeNode = iframe.contentWindow.document.createElement( 'div' );
 
-			domEmitter.listenTo( iframeNode, 'test', spy );
-			iframeNode.dispatchEvent( new Event( 'test' ) );
+				domEmitter.listenTo( iframeNode, 'test', spy );
+				iframeNode.dispatchEvent( new Event( 'test' ) );
 
-			sinon.assert.calledOnce( spy );
+				sinon.assert.calledOnce( spy );
+
+				iframe.remove();
+				done();
+			} );
+
+			document.body.appendChild( iframe );
 		} );
 
 		describe( 'event capturing', () => {
@@ -452,20 +458,26 @@ describe( 'DomEmitterMixin', () => {
 		} );
 
 		// #187
-		it( 'should work for DOM Nodes belonging to another window', () => {
+		it( 'should work for DOM Nodes belonging to another window', done => {
 			const spy = testUtils.sinon.spy();
 			const iframe = document.createElement( 'iframe' );
 
-			document.body.appendChild( iframe );
-			const iframeNode = iframe.contentWindow.document.createElement( 'div' );
+			iframe.addEventListener( 'load', () => {
+				const iframeNode = iframe.contentWindow.document.createElement( 'div' );
 
-			domEmitter.listenTo( iframeNode, 'test', spy );
+				domEmitter.listenTo( iframeNode, 'test', spy );
 
-			iframeNode.dispatchEvent( new Event( 'test' ) );
-			domEmitter.stopListening( iframeNode );
-			iframeNode.dispatchEvent( new Event( 'test' ) );
+				iframeNode.dispatchEvent( new Event( 'test' ) );
+				domEmitter.stopListening( iframeNode );
+				iframeNode.dispatchEvent( new Event( 'test' ) );
 
-			sinon.assert.calledOnce( spy );
+				sinon.assert.calledOnce( spy );
+
+				iframe.remove();
+				done();
+			} );
+
+			document.body.appendChild( iframe );
 		} );
 
 		describe( 'event capturing', () => {