diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js
index 6f5c92caba..2e079bc8cd 100644
--- a/js/tests/unit/scrollspy.js
+++ b/js/tests/unit/scrollspy.js
@@ -138,6 +138,104 @@ $(function () {
$scrollspy.scrollTop(350)
})
+ // This could be simplified/improved later
+ QUnit.test('should only switch "active" class on current target specified w jQuery element', function (assert) {
+ assert.expect(1)
+ var done = assert.async()
+
+ var sectionHTML = '
'
+ var $section = $(sectionHTML).appendTo('#qunit-fixture')
+
+ var $scrollspy = $section
+ .show()
+ .find('#scrollspy-example')
+ .bootstrapScrollspy({
+ target: $('#ss-target')
+ })
+
+ $scrollspy.one('scroll', function () {
+ assert.ok($section.hasClass('active'), '"active" class still on root node')
+ done()
+ })
+
+ $scrollspy.scrollTop(350)
+ })
+
+ // This could be simplified/improved later
+ QUnit.test('should only switch "active" class on current target specified without ID', function (assert) {
+ assert.expect(2)
+ var done = assert.async()
+
+ var sectionHTML = ''
+ var $section = $(sectionHTML).appendTo('#qunit-fixture')
+
+ var $scrollspy = $section
+ .show()
+ .find('#scrollspy-example')
+ .bootstrapScrollspy({
+ target: $('.container')
+ })
+
+ assert.ok($('.container').attr('id').length > 0, '`target` has an ID attribute')
+
+ $scrollspy.one('scroll', function () {
+ assert.ok($section.hasClass('active'), '"active" class still on root node')
+ done()
+ })
+
+ $scrollspy.scrollTop(350)
+ })
+
QUnit.test('should correctly select middle navigation option when large offset is used', function (assert) {
assert.expect(3)
var done = assert.async()
@@ -733,4 +831,43 @@ $(function () {
testOffsetMethod('js')
testOffsetMethod('data')
})
+
+ // This could be simplified/improved later
+ QUnit.test('should raise exception to avoid xss on target', function (assert) {
+ assert.expect(1)
+ assert.throws(function () {
+ var templateHTML = ''
+
+ $(templateHTML).appendTo(document.body)
+
+ $('#ss-target').bootstrapScrollspy({
+ target: '
'
+ })
+ }, /SyntaxError/)
+ })
})