1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-10 07:37:27 +02:00

Changes to Alert component to match the others (#33402)

Alert.js: Refactor code to match the other components
* Use this._element
* Remove handleDismiss method and keep its functionality on event
* Change JqueryInterface to be more generic
* Correct docs to be aligned with code, and add undocumented functionality
* Update alerts.md

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
GeoSot
2021-06-28 16:34:47 +03:00
committed by GitHub
parent 45d26de728
commit 70dd7f6ff5
3 changed files with 61 additions and 67 deletions

View File

@@ -2,7 +2,7 @@ import Alert from '../../src/alert'
import { getTransitionDurationFromElement } from '../../src/util/index'
/** Test helpers */
import { getFixture, clearFixture, jQueryMock } from '../helpers/fixture'
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
describe('Alert', () => {
let fixtureEl
@@ -102,25 +102,20 @@ describe('Alert', () => {
it('should not remove alert if close event is prevented', done => {
fixtureEl.innerHTML = '<div class="alert"></div>'
const alertEl = document.querySelector('.alert')
const getAlert = () => document.querySelector('.alert')
const alertEl = getAlert()
const alert = new Alert(alertEl)
const endTest = () => {
setTimeout(() => {
expect(alert._removeElement).not.toHaveBeenCalled()
done()
}, 10)
}
spyOn(alert, '_removeElement')
alertEl.addEventListener('close.bs.alert', event => {
event.preventDefault()
endTest()
setTimeout(() => {
expect(getAlert()).not.toBeNull()
done()
}, 10)
})
alertEl.addEventListener('closed.bs.alert', () => {
endTest()
throw new Error('should not fire closed event')
})
alert.close()
@@ -167,9 +162,9 @@ describe('Alert', () => {
jQueryMock.fn.alert = Alert.jQueryInterface
jQueryMock.elements = [alertEl]
expect(Alert.getInstance(alertEl)).toBeNull()
jQueryMock.fn.alert.call(jQueryMock, 'close')
expect(Alert.getInstance(alertEl)).not.toBeNull()
expect(fixtureEl.querySelector('.alert')).toBeNull()
})