Skip to content

Commit 3b99d9b

Browse files
committed
Added a test for container option
1 parent 272c2d9 commit 3b99d9b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/moveTo-spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ test('It should set defaults', (t) => {
4646
t.not(inst.options.duration, undefined);
4747
t.not(inst.options.easing, undefined);
4848
t.not(inst.options.callback, undefined);
49+
t.not(inst.options.container, undefined);
4950
});
5051

5152
test('It should pass ease function(s) when creating instance', (t) => {
@@ -148,3 +149,32 @@ test.serial.cb('It should scroll to target element', (t) => {
148149
}, 1000);
149150
});
150151

152+
test.serial.cb('It should scroll to target position inside an element', (t) => {
153+
const container = document.createElement('div');
154+
155+
document.body.appendChild(container);
156+
157+
const inst = new MoveTo({
158+
container: container
159+
});
160+
161+
const calls = [];
162+
163+
// mock scroll.
164+
const originalScroll = container.scroll;
165+
container.scroll = function(_, y) {
166+
calls.push(y);
167+
};
168+
169+
inst.move(1500);
170+
171+
setTimeout(() => {
172+
// revert scroll.
173+
container.scroll = originalScroll;
174+
175+
t.is(calls[calls.length - 1], 1500);
176+
177+
t.end();
178+
}, 1000);
179+
});
180+

0 commit comments

Comments
 (0)