Skip to content

Commit bcd5097

Browse files
committed
Merge pull request twbs#3655 from jorgenfb/8dda83906d72ade81ecf9b21d55b5a2922589d30
Updated unit test for tooltips. Now using is() instead of hasClass()
2 parents 7875e48 + 8dda839 commit bcd5097

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

js/bootstrap-tooltip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484
, leave: function (e) {
8585
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
8686

87+
if (this.timeout) clearTimeout(this.timeout)
8788
if (!self.options.delay || !self.options.delay.hide) return self.hide()
8889

89-
clearTimeout(this.timeout)
9090
self.hoverState = 'out'
9191
this.timeout = setTimeout(function() {
9292
if (self.hoverState == 'out') self.hide()
@@ -272,4 +272,4 @@
272272
, delay: 0
273273
}
274274

275-
}(window.jQuery);
275+
}(window.jQuery);

js/tests/unit/bootstrap-tooltip.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ $(function () {
3333
.tooltip({placement: 'bottom'})
3434
.tooltip('show')
3535

36-
ok($(".tooltip").hasClass('fade bottom in'), 'has correct classes applied')
36+
ok($(".tooltip").is('.fade.bottom.in'), 'has correct classes applied')
3737
tooltip.tooltip('hide')
3838
})
3939

@@ -69,10 +69,29 @@ $(function () {
6969
tooltip.trigger('mouseenter')
7070

7171
setTimeout(function () {
72-
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
72+
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
7373
tooltip.trigger('mouseout')
7474
setTimeout(function () {
75-
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
75+
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
76+
start()
77+
}, 200)
78+
}, 100)
79+
})
80+
81+
test("should not show tooltip if leave event occurs before delay expires, even if hide delay is 0", function () {
82+
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
83+
.appendTo('#qunit-fixture')
84+
.tooltip({ delay: { show: 200, hide: 0} })
85+
86+
stop()
87+
88+
tooltip.trigger('mouseenter')
89+
90+
setTimeout(function () {
91+
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
92+
tooltip.trigger('mouseout')
93+
setTimeout(function () {
94+
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
7695
start()
7796
}, 200)
7897
}, 100)
@@ -85,10 +104,10 @@ $(function () {
85104
stop()
86105
tooltip.trigger('mouseenter')
87106
setTimeout(function () {
88-
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
107+
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
89108
tooltip.trigger('mouseout')
90109
setTimeout(function () {
91-
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
110+
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
92111
start()
93112
}, 100)
94113
}, 50)
@@ -101,9 +120,9 @@ $(function () {
101120
stop()
102121
tooltip.trigger('mouseenter')
103122
setTimeout(function () {
104-
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
123+
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
105124
setTimeout(function () {
106-
ok(!$(".tooltip").hasClass('fade in'), 'tooltip has faded in')
125+
ok(!$(".tooltip").is('.fade.in'), 'tooltip has faded in')
107126
start()
108127
}, 200)
109128
}, 100)
@@ -133,4 +152,4 @@ $(function () {
133152
ok($.fn.tooltip.Constructor.prototype.isHTML($('<div></div>')), 'correctly detected html')
134153
})
135154

136-
})
155+
})

0 commit comments

Comments
 (0)