]>
git.ipfire.org Git - ipfire.org.git/blob - src/scss/bootstrap-4.0.0-alpha.6/js/tests/unit/alert.js
4 QUnit
.module('alert plugin')
6 QUnit
.test('should be defined on jquery object', function (assert
) {
8 assert
.ok($(document
.body
).alert
, 'alert method is defined')
11 QUnit
.module('alert', {
12 beforeEach: function () {
13 // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
14 $.fn
.bootstrapAlert
= $.fn
.alert
.noConflict()
16 afterEach: function () {
17 $.fn
.alert
= $.fn
.bootstrapAlert
18 delete $.fn
.bootstrapAlert
22 QUnit
.test('should provide no conflict', function (assert
) {
24 assert
.strictEqual($.fn
.alert
, undefined, 'alert was set back to undefined (org value)')
27 QUnit
.test('should return jquery collection containing the element', function (assert
) {
30 var $alert
= $el
.bootstrapAlert()
31 assert
.ok($alert
instanceof $, 'returns jquery collection')
32 assert
.strictEqual($alert
[0], $el
[0], 'collection contains element')
35 QUnit
.test('should fade element out on clicking .close', function (assert
) {
37 var alertHTML
= '<div class="alert alert-danger fade show">'
38 + '<a class="close" href="#" data-dismiss="alert">×</a>'
39 + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
42 var $alert
= $(alertHTML
).bootstrapAlert().appendTo($('#qunit-fixture'))
44 $alert
.find('.close').trigger('click')
46 assert
.strictEqual($alert
.hasClass('show'), false, 'remove .show class on .close click')
49 QUnit
.test('should remove element when clicking .close', function (assert
) {
51 var alertHTML
= '<div class="alert alert-danger fade show">'
52 + '<a class="close" href="#" data-dismiss="alert">×</a>'
53 + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
55 var $alert
= $(alertHTML
).appendTo('#qunit-fixture').bootstrapAlert()
57 assert
.notEqual($('#qunit-fixture').find('.alert').length
, 0, 'element added to dom')
59 $alert
.find('.close').trigger('click')
61 assert
.strictEqual($('#qunit-fixture').find('.alert').length
, 0, 'element removed from dom')
64 QUnit
.test('should not fire closed when close is prevented', function (assert
) {
66 var done
= assert
.async()
67 $('<div class="alert"/>')
68 .on('close.bs.alert', function (e
) {
70 assert
.ok(true, 'close event fired')
73 .on('closed.bs.alert', function () {
74 assert
.ok(false, 'closed event fired')
76 .bootstrapAlert('close')