aboutsummaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorJohann-S <[email protected]>2019-03-27 09:47:57 +0100
committerJohann-S <[email protected]>2019-07-23 14:23:50 +0200
commit747f0f4c7b01a3900c163bb9b11715fa2380faea (patch)
treebaf6c55dd3d769dc599beab12e2f43cc6c04ec29 /js/src
parent891a187059918d850981f585dc61ac42f456662b (diff)
downloadbootstrap-747f0f4c7b01a3900c163bb9b11715fa2380faea.tar.xz
bootstrap-747f0f4c7b01a3900c163bb9b11715fa2380faea.zip
test jquery interface for our alert plugin
Diffstat (limited to 'js/src')
-rw-r--r--js/src/alert/alert.spec.js48
1 files changed, 47 insertions, 1 deletions
diff --git a/js/src/alert/alert.spec.js b/js/src/alert/alert.spec.js
index cb7b57b7f..5cf314d22 100644
--- a/js/src/alert/alert.spec.js
+++ b/js/src/alert/alert.spec.js
@@ -2,7 +2,7 @@ import Alert from './alert'
import { makeArray, getTransitionDurationFromElement } from '../util/index'
/** Test helpers */
-import { getFixture, clearFixture } from '../../tests/helpers/fixture'
+import { getFixture, clearFixture, jQueryMock } from '../../tests/helpers/fixture'
describe('Alert', () => {
let fixtureEl
@@ -124,4 +124,50 @@ describe('Alert', () => {
expect(Alert._getInstance(alertEl)).toBeNull()
})
})
+
+ describe('_jQueryInterface', () => {
+ it('should handle config passed and toggle existing alert', () => {
+ fixtureEl.innerHTML = '<div class="alert"></div>'
+
+ const alertEl = fixtureEl.querySelector('.alert')
+ const alert = new Alert(alertEl)
+
+ spyOn(alert, 'close')
+
+ jQueryMock.fn.alert = Alert._jQueryInterface
+ jQueryMock.elements = [alertEl]
+
+ jQueryMock.fn.alert.call(jQueryMock, 'close')
+
+ expect(alert.close).toHaveBeenCalled()
+ })
+
+ it('should create new alert instance and call close', () => {
+ fixtureEl.innerHTML = '<div class="alert"></div>'
+
+ const alertEl = fixtureEl.querySelector('.alert')
+
+ jQueryMock.fn.alert = Alert._jQueryInterface
+ jQueryMock.elements = [alertEl]
+
+ jQueryMock.fn.alert.call(jQueryMock, 'close')
+
+ expect(Alert._getInstance(alertEl)).toBeDefined()
+ expect(fixtureEl.querySelector('.alert')).toBeNull()
+ })
+
+ it('should just create an alert instance without calling close', () => {
+ fixtureEl.innerHTML = '<div class="alert"></div>'
+
+ const alertEl = fixtureEl.querySelector('.alert')
+
+ jQueryMock.fn.alert = Alert._jQueryInterface
+ jQueryMock.elements = [alertEl]
+
+ jQueryMock.fn.alert.call(jQueryMock)
+
+ expect(Alert._getInstance(alertEl)).toBeDefined()
+ expect(fixtureEl.querySelector('.alert')).not.toBeNull()
+ })
+ })
})