diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js
index 90c95d7691..9a00221fd8 100644
--- a/js/tests/unit/scrollspy.js
+++ b/js/tests/unit/scrollspy.js
@@ -42,7 +42,8 @@ $(function () {
ok($topbar.find('.active', true))
})
- test('should only switch active class on current target', function () {
+ asyncTest('should only switch active class on current target', function () {
+ expect(1);
var sectionHTML = '
' +
'
' +
'
' +
@@ -75,7 +76,40 @@ $(function () {
.find('#scrollspy-example')
.bootstrapScrollspy({target: '#ss-target'})
+ $scrollSpy.on('scroll.bs.scrollspy', function () {
+ ok($section.hasClass('active'), 'Active class still on root node')
+ start()
+ })
$scrollSpy.scrollTop(350);
- ok($section.hasClass('active'), 'Active class still on root node')
+ })
+
+ asyncTest('middle navigation option correctly selected when large offset is used', function () {
+ expect(3);
+ var sectionHTML = '' +
+ '' +
+ '
' +
+ '' +
+ '' +
+ '' +
+ '
',
+ $section = $(sectionHTML).appendTo('#qunit-fixture'),
+ $scrollSpy = $section
+ .show()
+ .filter('#content')
+ $scrollSpy.bootstrapScrollspy({target: '#navigation', offset: $scrollSpy.position().top})
+
+ $scrollSpy.on('scroll.bs.scrollspy', function () {
+ ok(!$section.find('#one-link').parent().hasClass('active'), 'Active class removed from first section')
+ ok($section.find('#two-link').parent().hasClass('active'), 'Active class on middle section')
+ ok(!$section.find('#three-link').parent().hasClass('active'), 'Active class not on last section')
+ start()
+ })
+ $scrollSpy.scrollTop(550);
})
})