From 2ba61e04e923edaac09c92315212552f2d4ce676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Tue, 2 Mar 2021 11:27:11 -0300 Subject: [PATCH] fix(filechooser): cancel is sync (#6937) BREAKING CHANGE: FileChooser.cancel() is now synchronous. --- docs/api.md | 1 - src/common/FileChooser.ts | 2 +- test/input.spec.ts | 8 +++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index 357f1147..d88502df 100644 --- a/docs/api.md +++ b/docs/api.md @@ -2790,7 +2790,6 @@ await fileChooser.accept(['/tmp/myfile.pdf']); - returns: <[Promise]> #### fileChooser.cancel() -- returns: <[Promise]> Closes the file chooser without selecting any files. diff --git a/src/common/FileChooser.ts b/src/common/FileChooser.ts index 34069188..53fc70b9 100644 --- a/src/common/FileChooser.ts +++ b/src/common/FileChooser.ts @@ -75,7 +75,7 @@ export class FileChooser { /** * Closes the file chooser without selecting any files. */ - async cancel(): Promise { + cancel() { assert( !this._handled, 'Cannot cancel FileChooser which is already handled!' diff --git a/test/input.spec.ts b/test/input.spec.ts index d87aa137..92443563 100644 --- a/test/input.spec.ts +++ b/test/input.spec.ts @@ -295,7 +295,13 @@ describe('input tests', function () { ]); await fileChooser.cancel(); let error = null; - await fileChooser.cancel().catch((error_) => (error = error_)); + + try { + fileChooser.cancel(); + } catch (error_) { + error = error_; + } + expect(error.message).toBe( 'Cannot cancel FileChooser which is already handled!' );