Skip to content

Commit

Permalink
Merge pull request twbs#3655 from jorgenfb/8dda83906d72ade81ecf9b21d5…
Browse files Browse the repository at this point in the history
…5b5a2922589d30

Updated unit test for tooltips. Now using is() instead of hasClass()
  • Loading branch information
fat committed May 31, 2012
2 parents 7875e48 + 8dda839 commit bcd5097
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions js/bootstrap-tooltip.js
Expand Up @@ -84,9 +84,9 @@
, leave: function (e) {
var self = $(e.currentTarget)[this.type](this._options).data(this.type)

if (this.timeout) clearTimeout(this.timeout)
if (!self.options.delay || !self.options.delay.hide) return self.hide()

clearTimeout(this.timeout)
self.hoverState = 'out'
this.timeout = setTimeout(function() {
if (self.hoverState == 'out') self.hide()
Expand Down Expand Up @@ -272,4 +272,4 @@
, delay: 0
}

}(window.jQuery);
}(window.jQuery);
35 changes: 27 additions & 8 deletions js/tests/unit/bootstrap-tooltip.js
Expand Up @@ -33,7 +33,7 @@ $(function () {
.tooltip({placement: 'bottom'})
.tooltip('show')

ok($(".tooltip").hasClass('fade bottom in'), 'has correct classes applied')
ok($(".tooltip").is('.fade.bottom.in'), 'has correct classes applied')
tooltip.tooltip('hide')
})

Expand Down Expand Up @@ -69,10 +69,29 @@ $(function () {
tooltip.trigger('mouseenter')

setTimeout(function () {
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
start()
}, 200)
}, 100)
})

test("should not show tooltip if leave event occurs before delay expires, even if hide delay is 0", function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({ delay: { show: 200, hide: 0} })

stop()

tooltip.trigger('mouseenter')

setTimeout(function () {
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
start()
}, 200)
}, 100)
Expand All @@ -85,10 +104,10 @@ $(function () {
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
start()
}, 100)
}, 50)
Expand All @@ -101,9 +120,9 @@ $(function () {
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in')
ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
setTimeout(function () {
ok(!$(".tooltip").hasClass('fade in'), 'tooltip has faded in')
ok(!$(".tooltip").is('.fade.in'), 'tooltip has faded in')
start()
}, 200)
}, 100)
Expand Down Expand Up @@ -133,4 +152,4 @@ $(function () {
ok($.fn.tooltip.Constructor.prototype.isHTML($('<div></div>')), 'correctly detected html')
})

})
})

0 comments on commit bcd5097

Please sign in to comment.