Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve coverage for our Alert plugin
  • Loading branch information
Johann-S committed Mar 26, 2018
commit b5c362cf1ac2df82937d5c02cd94916a01aefb16
6 changes: 4 additions & 2 deletions js/src/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ const Alert = (($) => {
// Public

close(element) {
element = element || this._element
let rootElement = this._element
if (element) {
rootElement = this._getRootElement(element)
}

const rootElement = this._getRootElement(element)
const customEvent = this._triggerCloseEvent(rootElement)

if (customEvent.isDefaultPrevented()) {
Expand Down
1 change: 1 addition & 0 deletions js/tests/unit/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"globals": {
"sinon": false,
"Util": false,
"Alert": false,
"Button": false
},
"parserOptions": {
Expand Down
39 changes: 39 additions & 0 deletions js/tests/unit/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,43 @@ $(function () {
})
.bootstrapAlert('close')
})

QUnit.test('close should use internal _element if no element provided', function (assert) {
assert.expect(1)

var done = assert.async()
var $el = $('<div/>')
var $alert = $el.bootstrapAlert()
var alertInstance = $alert.data('bs.alert')

$alert.one('closed.bs.alert', function () {
assert.ok('alert closed')
done()
})

alertInstance.close()
})

QUnit.test('dispose should remove data and the element', function (assert) {
assert.expect(2)

var $el = $('<div/>')
var $alert = $el.bootstrapAlert()

assert.ok(typeof $alert.data('bs.alert') !== 'undefined')

$alert.data('bs.alert').dispose()

assert.ok(typeof $alert.data('bs.button') === 'undefined')
})

QUnit.test('should return alert version', function (assert) {
assert.expect(1)

if (typeof Alert !== 'undefined') {
assert.ok(typeof Alert.VERSION === 'string')
} else {
assert.notOk()
}
})
})