diff --git a/src/instanceMethods/_main.js b/src/instanceMethods/_main.js index 1d6fdedfd..6c82af11d 100644 --- a/src/instanceMethods/_main.js +++ b/src/instanceMethods/_main.js @@ -44,19 +44,11 @@ export function _main (userParams) { // functions to handle all resolving/rejecting/settling const succeedWith = (value) => { constructor.closePopup(innerParams.onClose, innerParams.onAfterClose) // TODO: make closePopup an *instance* method - if (innerParams.useRejections) { - resolve(value) - } else { - resolve({ value }) - } + resolve({ value }) } const dismissWith = (dismiss) => { constructor.closePopup(innerParams.onClose, innerParams.onAfterClose) - if (innerParams.useRejections) { - reject(dismiss) - } else { - resolve({ dismiss }) - } + resolve({ dismiss }) } const errorWith = (error) => { constructor.closePopup(innerParams.onClose, innerParams.onAfterClose) @@ -107,28 +99,16 @@ export function _main (userParams) { if (innerParams.preConfirm) { this.resetValidationMessage() const preConfirmPromise = Promise.resolve().then(() => innerParams.preConfirm(value, innerParams.extraParams)) - if (innerParams.expectRejections) { - preConfirmPromise.then( - (preConfirmValue) => succeedWith(preConfirmValue || value), - (validationMessage) => { + preConfirmPromise.then( + (preConfirmValue) => { + if (dom.isVisible(domCache.validationMessage) || preConfirmValue === false) { this.hideLoading() - if (validationMessage) { - this.showValidationMessage(validationMessage) - } + } else { + succeedWith(preConfirmValue || value) } - ) - } else { - preConfirmPromise.then( - (preConfirmValue) => { - if (dom.isVisible(domCache.validationMessage) || preConfirmValue === false) { - this.hideLoading() - } else { - succeedWith(preConfirmValue || value) - } - }, - (error) => errorWith(error) - ) - } + }, + (error) => errorWith(error) + ) } else { succeedWith(value) } @@ -152,35 +132,18 @@ export function _main (userParams) { if (innerParams.inputValidator) { this.disableInput() const validationPromise = Promise.resolve().then(() => innerParams.inputValidator(inputValue, innerParams.extraParams)) - if (innerParams.expectRejections) { - validationPromise.then( - () => { - this.enableButtons() - this.enableInput() + validationPromise.then( + (validationMessage) => { + this.enableButtons() + this.enableInput() + if (validationMessage) { + this.showValidationMessage(validationMessage) + } else { confirm(inputValue) - }, - (validationMessage) => { - this.enableButtons() - this.enableInput() - if (validationMessage) { - this.showValidationMessage(validationMessage) - } } - ) - } else { - validationPromise.then( - (validationMessage) => { - this.enableButtons() - this.enableInput() - if (validationMessage) { - this.showValidationMessage(validationMessage) - } else { - confirm(inputValue) - } - }, - error => errorWith(error) - ) - } + }, + error => errorWith(error) + ) } else if (!this.getInput().checkValidity()) { this.enableButtons() this.showValidationMessage(innerParams.validationMessage) diff --git a/src/utils/params.js b/src/utils/params.js index f9df4aec2..ff6d68179 100644 --- a/src/utils/params.js +++ b/src/utils/params.js @@ -63,14 +63,10 @@ const defaultParams = { onBeforeOpen: null, onAfterClose: null, onOpen: null, - onClose: null, - useRejections: false, - expectRejections: false + onClose: null } export const deprecatedParams = [ - 'useRejections', - 'expectRejections', 'extraParams' ] diff --git a/src/utils/setParameters.js b/src/utils/setParameters.js index 8027755fd..e41e05e99 100644 --- a/src/utils/setParameters.js +++ b/src/utils/setParameters.js @@ -15,7 +15,7 @@ export default function setParameters (params) { if (!params.inputValidator) { Object.keys(defaultInputValidators).forEach((key) => { if (params.input === key) { - params.inputValidator = params.expectRejections ? defaultInputValidators[key] : sweetAlert.adaptInputValidator(defaultInputValidators[key]) + params.inputValidator = sweetAlert.adaptInputValidator(defaultInputValidators[key]) } }) } diff --git a/sweetalert2.d.ts b/sweetalert2.d.ts index e79c3af43..ff87824c3 100644 --- a/sweetalert2.d.ts +++ b/sweetalert2.d.ts @@ -20,13 +20,7 @@ declare module 'sweetalert2' { * timer: 2000 * }) */ - function swal(settings: SweetAlertOptions & { useRejections?: false }): Promise; - - /** - * @deprecated - * swal() overload for legacy alerts that use { useRejections: true }. - */ - function swal(settings: SweetAlertOptions & { useRejections: true }): Promise; + function swal(settings: SweetAlertOptions): Promise; /** * A namespace inside the default function, containing utility function for controlling the currently-displayed @@ -861,15 +855,6 @@ declare module 'sweetalert2' { * @default null */ onClose?: (modalElement: HTMLElement) => void; - - /** - * Determines whether given `inputValidator` and `preConfirm` functions should be expected to to signal - * validation message by rejecting, or by their respective means (see documentation for each option). - * - * @default false - * @deprecated - */ - expectRejections?: boolean; } export default swal; diff --git a/test/qunit/deprecated.js b/test/qunit/deprecated.js deleted file mode 100644 index 0d0132075..000000000 --- a/test/qunit/deprecated.js +++ /dev/null @@ -1,171 +0,0 @@ -const { $, Swal, SwalWithoutAnimation, triggerKeydownEvent, isVisible } = require('./helpers') - -QUnit.test('confirm button /w useRejections: true', (assert) => { - const done = assert.async() - - SwalWithoutAnimation({ - title: 'Confirm me', - useRejections: true - }).then((result) => { - assert.equal(result, true) - done() - }) - - Swal.clickConfirm() -}) - -QUnit.test('cancel button /w useRejections: true', (assert) => { - const done = assert.async() - - SwalWithoutAnimation({ - title: 'Cancel me', - useRejections: true - }).then( - () => {}, - (dismiss) => { - assert.equal(dismiss, Swal.DismissReason.cancel) - done() - } - ) - - Swal.clickCancel() -}) - -QUnit.test('esc key /w useRejections: true', (assert) => { - const done = assert.async() - - SwalWithoutAnimation({ - title: 'Esc me', - useRejections: true - }).then( - () => {}, - (dismiss) => { - assert.equal(dismiss, Swal.DismissReason.esc) - done() - } - ) - - triggerKeydownEvent(Swal.getPopup(), 'Escape') -}) - -QUnit.test('backdrop click /w useRejections: true', (assert) => { - const done = assert.async() - - Swal({ - title: 'Backdrop click', - useRejections: true - }).then( - () => {}, - (dismiss) => { - assert.equal(dismiss, Swal.DismissReason.backdrop) - done() - } - ) - - $('.swal2-container').click() -}) - -QUnit.test('timer /w useRejections: true', (assert) => { - const done = assert.async() - - SwalWithoutAnimation({ - title: 'Timer test', - timer: 10, - useRejections: true - }).then( - () => {}, - (dismiss) => { - assert.equal(dismiss, Swal.DismissReason.timer) - done() - } - ) -}) - -QUnit.test('close button /w useRejections: true', (assert) => { - const done = assert.async() - - Swal({ - title: 'Close button test', - showCloseButton: true, - useRejections: true - }).then( - () => {}, - (dismiss) => { - assert.equal(dismiss, Swal.DismissReason.close) - done() - } - ) - - const closeButton = $('.swal2-close') - assert.ok(isVisible(closeButton)) - closeButton.click() -}) - -QUnit.test('input text /w useRejections: true', (assert) => { - const done = assert.async() - - const string = 'Live for yourself' - Swal({ - input: 'text', - useRejections: true - }).then((result) => { - assert.equal(result, string) - done() - }) - - $('.swal2-input').value = string - Swal.clickConfirm() -}) - -QUnit.test('built-in email validation /w useRejections: true', (assert) => { - const done = assert.async() - - const validEmailAddress = 'team+support+a.b@example.com' - Swal({ - input: 'email', - useRejections: true - }).then((result) => { - assert.equal(result, validEmailAddress) - done() - }) - - $('.swal2-input').value = validEmailAddress - Swal.clickConfirm() -}) - -QUnit.test('input select /w useRejections: true', (assert) => { - const done = assert.async() - - const selected = 'dos' - Swal({ - input: 'select', - inputOptions: { uno: 1, dos: 2 }, - useRejections: true - }).then((result) => { - assert.equal(result, selected) - done() - }) - - $('.swal2-select').value = selected - Swal.clickConfirm() -}) - -QUnit.test('input checkbox /w useRejections: true', (assert) => { - const done = assert.async() - - Swal({ - input: 'checkbox', - inputAttributes: { - name: 'test-checkbox' - }, - useRejections: true - }).then((result) => { - assert.equal(checkbox.getAttribute('name'), 'test-checkbox') - assert.equal(result, '1') - done() - }) - - const checkbox = $('.swal2-checkbox input') - checkbox.checked = true - Swal.clickConfirm() -}) diff --git a/test/qunit/tests.js b/test/qunit/tests.js index 520e838da..6a3ea0fa2 100644 --- a/test/qunit/tests.js +++ b/test/qunit/tests.js @@ -690,7 +690,7 @@ QUnit.test('on errors in *async* user-defined functions, cleans up and propagate } // inputValidator - const rejectedPromise = Swal({ input: 'text', expectRejections: false, inputValidator: erroringFunction }) + const rejectedPromise = Swal({ input: 'text', inputValidator: erroringFunction }) Swal.clickConfirm() rejectedPromise.catch((error) => { assert.equal(error, expectedError) // error is bubbled up back to user code @@ -698,7 +698,7 @@ QUnit.test('on errors in *async* user-defined functions, cleans up and propagate assert.notOk(Swal.isVisible()) // display is cleaned up // preConfirm - const rejectedPromise = Swal({ expectRejections: false, preConfirm: erroringFunction }) + const rejectedPromise = Swal({ preConfirm: erroringFunction }) Swal.clickConfirm() rejectedPromise.catch((error) => { assert.equal(error, expectedError) // error is bubbled up back to user code