Skip to content

Commit

Permalink
fix(api): falsy values in preConfirm (#1403)
Browse files Browse the repository at this point in the history
* Changed check on preConfirmValue

Currently the check on preConfirmValue is done on a falsy value. This include also 0,
which could be a valid return value.

Replaced it with a check for udnefined value, which is the only case
where we may want to return something else

* Added test for preConfirm returning undefined

* Changed test for preConfirm return value

Testing the code that causes the issue this time.
  • Loading branch information
gverni authored and limonte committed Feb 5, 2019
1 parent a1bd5e9 commit f6e1a30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/instanceMethods/_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function _main (userParams) {
if (dom.isVisible(domCache.validationMessage) || preConfirmValue === false) {
this.hideLoading()
} else {
succeedWith(preConfirmValue || value)
succeedWith(typeof (preConfirmValue) === 'undefined' ? value : preConfirmValue)
}
}
)
Expand Down
15 changes: 15 additions & 0 deletions test/qunit/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,3 +766,18 @@ QUnit.test('Custom content', (assert) => {
done()
})
})

QUnit.test('preConfirm returns 0', (assert) => {
const done = assert.async()
SwalWithoutAnimation.fire({
onOpen: () => {
Swal.clickConfirm()
},
preConfirm: () => {
return 0
}
}).then(result => {
assert.equal(result.value, 0)
done()
})
})

0 comments on commit f6e1a30

Please sign in to comment.