Browse Source

Improve teardown. The previous solution did affect other tests.

Piotrek Koszuliński 6 năm trước cách đây
mục cha
commit
4bf2e121bb

+ 6 - 4
packages/ckeditor-cloud-services-core/tests/token/token.js

@@ -14,14 +14,16 @@ describe( 'Token', () => {
 	beforeEach( () => {
 		requests = [];
 
-		global.xhr = sinon.useFakeXMLHttpRequest();
+		const xhr = sinon.useFakeXMLHttpRequest();
 
-		global.xhr.onCreate = xhr => {
-			requests.push( xhr );
+		xhr.onCreate = request => {
+			requests.push( request );
 		};
 	} );
 
-	afterEach( () => global.xhr.restore() );
+	afterEach( () => {
+		sinon.restore();
+	} );
 
 	describe( 'constructor()', () => {
 		it( 'should throw error when no tokenUrl provided', () => {

+ 12 - 8
packages/ckeditor-cloud-services-core/tests/uploadgateway/fileuploader.js

@@ -98,14 +98,16 @@ describe( 'FileUploader', () => {
 		let request;
 
 		beforeEach( () => {
-			global.xhr = sinon.useFakeXMLHttpRequest();
+			const xhr = sinon.useFakeXMLHttpRequest();
 
-			global.xhr.onCreate = xhr => {
-				request = xhr;
+			xhr.onCreate = r => {
+				request = r;
 			};
 		} );
 
-		afterEach( () => global.xhr.restore() );
+		afterEach( () => {
+			sinon.restore();
+		} );
 
 		it( 'should sent request with correct data (url, method, type, headers)', done => {
 			fileUploader
@@ -200,14 +202,16 @@ describe( 'FileUploader', () => {
 		let request;
 
 		beforeEach( () => {
-			global.xhr = sinon.useFakeXMLHttpRequest();
+			const xhr = sinon.useFakeXMLHttpRequest();
 
-			global.xhr.onCreate = xhr => {
-				request = xhr;
+			xhr.onCreate = r => {
+				request = r;
 			};
 		} );
 
-		afterEach( () => global.xhr.restore() );
+		afterEach( () => {
+			sinon.restore();
+		} );
 
 		it( 'should abort xhr request', () => {
 			fileUploader.send();