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 in">'
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>'
41 var $alert = $(alertHTML).bootstrapAlert()
43 $alert.find('.close').trigger('click')
45 assert.strictEqual($alert.hasClass('in'), false, 'remove .in class on .close click')
48 QUnit.test('should remove element when clicking .close', function (assert) {
50 var alertHTML = '<div class="alert alert-danger fade in">'
51 + '<a class="close" href="#" data-dismiss="alert">×</a>'
52 + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
54 var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert()
56 assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom')
58 $alert.find('.close').trigger('click')
60 assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom')
63 QUnit.test('should not fire closed when close is prevented', function (assert) {
65 var done = assert.async()
66 $('<div class="alert"/>')
67 .on('close.bs.alert', function (e) {
69 assert.ok(true, 'close event fired')
72 .on('closed.bs.alert', function () {
73 assert.ok(false, 'closed event fired')
75 .bootstrapAlert('close')