Skip to content

Commit fc48ff1

Browse files
committed
Tests for relative scroll feature
1 parent 91e3fa0 commit fc48ff1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/tests.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,49 @@ QUnit.test('Scrolls the #scrollable element, or not.', function(assert) {
5555
});
5656
});
5757
});
58+
59+
QUnit.test('Scrolls the #scrollable element to absolute or relative scroll position', function(assert) {
60+
var done = assert.async(3);
61+
62+
var finalScroll = function() {
63+
$.smoothScroll({
64+
scrollElement: $('#scrollable'),
65+
speed: 100,
66+
afterScroll: function() {
67+
var scrollTop = $('#scrollable').scrollTop();
68+
assert.equal(scrollTop, 10, '#scrollable element scrolls back to 10');
69+
70+
// Trigger the next scroll, which should actually work
71+
done();
72+
}
73+
}, 10);
74+
};
75+
76+
$.smoothScroll({
77+
scrollElement: $('#scrollable'),
78+
speed: 100,
79+
afterScroll: function() {
80+
var scrollTop = $('#scrollable').scrollTop();
81+
assert.equal(scrollTop, 15, '#scrollable element scrolls to 15');
82+
83+
// Trigger the next scroll, which should actually work
84+
$('#scrollit').trigger('click');
85+
done();
86+
}
87+
}, 15);
88+
89+
$('#scrollit').bind('click', function(event) {
90+
event.preventDefault();
91+
92+
$.smoothScroll({
93+
scrollElement: $('#scrollable'),
94+
speed: 100,
95+
afterScroll: function() {
96+
var scrollTop = $('#scrollable').scrollTop();
97+
assert.equal(scrollTop, 25, '#scrollable element scrolls "+=10" to 25');
98+
done();
99+
finalScroll();
100+
}
101+
}, '+=10');
102+
});
103+
});

0 commit comments

Comments
 (0)