6 test('should be defined on jquery object', function () {
7 ok($(document.body).affix, 'affix method is defined')
12 // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
13 $.fn.bootstrapAffix = $.fn.affix.noConflict()
15 teardown: function () {
16 $.fn.affix = $.fn.bootstrapAffix
17 delete $.fn.bootstrapAffix
21 test('should provide no conflict', function () {
22 ok(!$.fn.affix, 'affix was set back to undefined (org value)')
25 test('should return element', function () {
26 ok($(document.body).bootstrapAffix()[0] == document.body, 'document.body returned')
29 test('should exit early if element is not visible', function () {
30 var $affix = $('<div style="display: none"></div>').bootstrapAffix()
31 $affix.data('bs.affix').checkPosition()
32 ok(!$affix.hasClass('affix'), 'affix class was not added')
35 test('should trigger affixed event after affix', function () {
38 var template = $('<div id="affixTarget"><ul><li>Please affix</li><li>And unaffix</li></ul></div><div id="affixAfter" style="height: 20000px; display:block;"></div>')
39 template.appendTo('body')
41 $('#affixTarget').bootstrapAffix({
42 offset: $('#affixTarget ul').position()
46 .on('affix.bs.affix', function () {
47 ok(true, 'affix event triggered')
48 }).on('affixed.bs.affix', function () {
49 ok(true, 'affixed event triggered')
50 $('#affixTarget').remove()
51 $('#affixAfter').remove()
55 setTimeout(function () {
56 window.scrollTo(0, document.body.scrollHeight)
57 setTimeout(function () {