Skip to content

Instantly share code, notes, and snippets.

@hnrch02

hnrch02/test.js Secret

Created March 1, 2015 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnrch02/434c11d59153663b999c to your computer and use it in GitHub Desktop.
Save hnrch02/434c11d59153663b999c to your computer and use it in GitHub Desktop.
QUnit.test('should add the active class correctly when there are nested elements at 0 scroll offset', function (assert) {
var times = 0
var done = assert.async()
var navbarHtml = '<nav class="navbar">'
+ '<ul class="nav">'
+ '<li id="li-1"><a href="#div-1">div 1</a>'
+ '<ul>'
+ '<li id="li-2"><a href="#div-2">div 2</a></li>'
+ '</ul>'
+ '</li>'
+ '</ul>'
+ '</nav>'
var contentHtml = '<div class="content" style="position: absolute; top: 0px; overflow: auto; height: 50px">'
+ '<div id="div-1" style="padding: 0; margin: 0">'
+ '<div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>'
+ '</div>'
+ '</div>'
$(navbarHtml).appendTo('#qunit-fixture')
var $content = $(contentHtml)
.appendTo('#qunit-fixture')
.bootstrapScrollspy({ offset: 0, target: '.navbar' })
!function testActiveElements() {
if (++times == 2) return done()
$content.one('scroll', function () {
assert.ok($('#li-1').hasClass('active'), 'nav item for outer element has "active" class')
assert.ok($('#li-2').hasClass('active'), 'nav item for inner element has "active" class')
testActiveElements()
})
$content.scrollTop($content.scrollTop() + 10)
}()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment