This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,12 @@ export default class FileRepository extends Plugin {
188188 } ) ;
189189 }
190190
191+ // Catch the file promise rejection. If there are no `catch` clause, the browser
192+ // will throw an error (see https://github.com/ckeditor/ckeditor5-upload/pull/90).
193+ loader . file . catch ( ( ) => {
194+ // The error will be handled by `FileLoader` so no action is required here.
195+ } ) ;
196+
191197 loader . on ( 'change:uploaded' , ( ) => {
192198 let aggregatedUploaded = 0 ;
193199
Original file line number Diff line number Diff line change @@ -200,6 +200,24 @@ describe( 'FileRepository', () => {
200200 expect ( fileRepository . uploadTotal ) . to . equal ( 500 ) ;
201201 expect ( fileRepository . uploadedPercent ) . to . equal ( 20 ) ;
202202 } ) ;
203+
204+ it ( 'should catch if file promise rejected (file)' , ( ) => {
205+ const catchSpy = testUtils . sinon . spy ( Promise . prototype , 'catch' ) ;
206+
207+ fileRepository . createLoader ( createNativeFileMock ( ) ) ;
208+
209+ // One call originates from `loader._createFilePromiseWrapper()` and other from `fileRepository.createLoader()`.
210+ expect ( catchSpy . callCount ) . to . equal ( 2 ) ;
211+ } ) ;
212+
213+ it ( 'should catch if file promise rejected (promise)' , ( ) => {
214+ const catchSpy = testUtils . sinon . spy ( Promise . prototype , 'catch' ) ;
215+
216+ fileRepository . createLoader ( new Promise ( ( ) => { } ) ) ;
217+
218+ // One call originates from `loader._createFilePromiseWrapper()` and other from `fileRepository.createLoader()`.
219+ expect ( catchSpy . callCount ) . to . equal ( 2 ) ;
220+ } ) ;
203221 } ) ;
204222
205223 describe ( 'getLoader()' , ( ) => {
You can’t perform that action at this time.
0 commit comments