From fc70cf908d1e133fed638eaf121e3ad5ec588989 Mon Sep 17 00:00:00 2001 From: Limon Monte Date: Thu, 17 Jan 2019 12:48:48 +0200 Subject: [PATCH] BREAKING CHANGE: inputValidator and preConfirm should always resolve (#1383) BREAKING CHANGE: inputValidator and preConfirm should always resolve (#1383) --- src/SweetAlert.js | 8 ++------ src/instanceMethods/_main.js | 14 ++++---------- test/qunit/tests.js | 31 ------------------------------- 3 files changed, 6 insertions(+), 47 deletions(-) diff --git a/src/SweetAlert.js b/src/SweetAlert.js index 4fdc7576a..cb9ecc945 100644 --- a/src/SweetAlert.js +++ b/src/SweetAlert.js @@ -37,13 +37,9 @@ function SweetAlert (...args) { } // `catch` cannot be the name of a module export, so we define our thenable methods here instead -SweetAlert.prototype.then = function (onFulfilled, onRejected) { +SweetAlert.prototype.then = function (onFulfilled) { const promise = privateProps.promise.get(this) - return promise.then(onFulfilled, onRejected) -} -SweetAlert.prototype.catch = function (onRejected) { - const promise = privateProps.promise.get(this) - return promise.catch(onRejected) + return promise.then(onFulfilled) } SweetAlert.prototype.finally = function (onFinally) { const promise = privateProps.promise.get(this) diff --git a/src/instanceMethods/_main.js b/src/instanceMethods/_main.js index 9fa42dd10..750e91259 100644 --- a/src/instanceMethods/_main.js +++ b/src/instanceMethods/_main.js @@ -40,8 +40,8 @@ export function _main (userParams) { const constructor = this.constructor - return new Promise((resolve, reject) => { - // functions to handle all resolving/rejecting/settling + return new Promise((resolve) => { + // functions to handle all closings/dismissals const succeedWith = (value) => { constructor.closePopup(innerParams.onClose, innerParams.onAfterClose) // TODO: make closePopup an *instance* method resolve({ value }) @@ -50,10 +50,6 @@ export function _main (userParams) { constructor.closePopup(innerParams.onClose, innerParams.onAfterClose) resolve({ dismiss }) } - const errorWith = (error) => { - constructor.closePopup(innerParams.onClose, innerParams.onAfterClose) - reject(error) - } // Close on timer if (innerParams.timer) { @@ -106,8 +102,7 @@ export function _main (userParams) { } else { succeedWith(preConfirmValue || value) } - }, - (error) => errorWith(error) + } ) } else { succeedWith(value) @@ -141,8 +136,7 @@ export function _main (userParams) { } else { confirm(inputValue) } - }, - error => errorWith(error) + } ) } else if (!this.getInput().checkValidity()) { this.enableButtons() diff --git a/test/qunit/tests.js b/test/qunit/tests.js index cfa9f337b..a14108f8b 100644 --- a/test/qunit/tests.js +++ b/test/qunit/tests.js @@ -666,37 +666,6 @@ QUnit.test('confirm button', (assert) => { Swal.clickConfirm() }) -QUnit.test('on errors in *async* user-defined functions, cleans up and propagates the error', (assert) => { - const done = assert.async() - - const expectedError = new Error('my bad') - const erroringFunction = () => { - return Promise.reject(expectedError) - } - - // inputValidator - const rejectedPromise = SwalWithoutAnimation.fire({ input: 'text', inputValidator: erroringFunction }) - Swal.clickConfirm() - rejectedPromise.catch((error) => { - assert.equal(error, expectedError) // error is bubbled up back to user code - setTimeout(() => { - assert.notOk(Swal.isVisible()) // display is cleaned up - - // preConfirm - const rejectedPromise = SwalWithoutAnimation.fire({ preConfirm: erroringFunction }) - Swal.clickConfirm() - rejectedPromise.catch((error) => { - assert.equal(error, expectedError) // error is bubbled up back to user code - setTimeout(() => { - assert.notOk(Swal.isVisible()) // display is cleaned up - - done() - }) - }) - }) - }) -}) - QUnit.test('params validation', (assert) => { assert.ok(Swal.isValidParameter('title')) assert.notOk(Swal.isValidParameter('foobar'))