Kaynağa Gözat

Tests: Check if file promise always has a `catch` clause.

Krzysztof Krztoń 6 yıl önce
ebeveyn
işleme
420b6164ef

+ 18 - 0
packages/ckeditor5-upload/tests/filerepository.js

@@ -200,6 +200,24 @@ describe( 'FileRepository', () => {
 			expect( fileRepository.uploadTotal ).to.equal( 500 );
 			expect( fileRepository.uploadedPercent ).to.equal( 20 );
 		} );
+
+		it( 'should catch if file promise rejected (file)', () => {
+			const catchSpy = testUtils.sinon.spy( Promise.prototype, 'catch' );
+
+			fileRepository.createLoader( createNativeFileMock() );
+
+			// One call originates from `loader._createFilePromiseWrapper()` and other from `fileRepository.createLoader()`.
+			expect( catchSpy.callCount ).to.equal( 2 );
+		} );
+
+		it( 'should catch if file promise rejected (promise)', () => {
+			const catchSpy = testUtils.sinon.spy( Promise.prototype, 'catch' );
+
+			fileRepository.createLoader( new Promise( () => {} ) );
+
+			// One call originates from `loader._createFilePromiseWrapper()` and other from `fileRepository.createLoader()`.
+			expect( catchSpy.callCount ).to.equal( 2 );
+		} );
 	} );
 
 	describe( 'getLoader()', () => {