diff --git a/js/src/alert.js b/js/src/alert.js index cd31c00999b5..8772c0de7c33 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -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()) { diff --git a/js/tests/karma.conf.js b/js/tests/karma.conf.js index a2b0a676bdcd..eceaa7ff7275 100644 --- a/js/tests/karma.conf.js +++ b/js/tests/karma.conf.js @@ -60,10 +60,10 @@ module.exports = (config) => { thresholds: { emitWarning: false, global: { - statements: 89, - lines: 89, - branches: 83, - functions: 84 + statements: 90, + branches: 84, + functions: 87, + lines: 90 } } } diff --git a/js/tests/unit/.eslintrc.json b/js/tests/unit/.eslintrc.json index 93aaa05f821a..0896f406d0f5 100644 --- a/js/tests/unit/.eslintrc.json +++ b/js/tests/unit/.eslintrc.json @@ -7,7 +7,9 @@ "globals": { "bootstrap": false, "sinon": false, - "Util": false + "Util": false, + "Alert": false, + "Button": false }, "parserOptions": { "ecmaVersion": 5, diff --git a/js/tests/unit/alert.js b/js/tests/unit/alert.js index 165c91f1e14f..fc7727fb1c05 100644 --- a/js/tests/unit/alert.js +++ b/js/tests/unit/alert.js @@ -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 = $('
') + 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 = $('') + 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() + } + }) }) diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index cc2719c3a085..1fdcce95fd7c 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -172,4 +172,27 @@ $(function () { assert.ok($btn.is(':not(.active)'), 'button did not become active') assert.ok(!$input.is(':checked'), 'checkbox did not get checked') }) + + QUnit.test('dispose should remove data and the element', function (assert) { + assert.expect(2) + + var $el = $('') + var $button = $el.bootstrapButton() + + assert.ok(typeof $button.data('bs.button') !== 'undefined') + + $button.data('bs.button').dispose() + + assert.ok(typeof $button.data('bs.button') === 'undefined') + }) + + QUnit.test('should return button version', function (assert) { + assert.expect(1) + + if (typeof Button !== 'undefined') { + assert.ok(typeof Button.VERSION === 'string') + } else { + assert.notOk() + } + }) }) diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 0e3d3704137d..726655e9ccce 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -940,4 +940,116 @@ $(function () { $dropdown.trigger('click') }) + + QUnit.test('should call Popper.js and detect navbar on update', function (assert) { + assert.expect(3) + + var dropdownHTML = + '