forked from malte-wessel/react-custom-scrollbars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonUpdate.js
66 lines (63 loc) · 2.31 KB
/
onUpdate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Scrollbars } from 'react-custom-scrollbars';
import { render, unmountComponentAtNode } from 'react-dom';
import React from 'react';
export default function createTests() {
let node;
beforeEach(() => {
node = document.createElement('div');
document.body.appendChild(node);
});
afterEach(() => {
unmountComponentAtNode(node);
document.body.removeChild(node);
});
describe('onUpdate', () => {
describe('when scrolling x-axis', () => {
it('should call `onUpdate`', done => {
const spy = createSpy();
render((
<Scrollbars style={{ width: 100, height: 100 }} onUpdate={spy}>
<div style={{ width: 200, height: 200 }}/>
</Scrollbars>
), node, function callback() {
this.scrollLeft(50);
setTimeout(() => {
expect(spy.calls.length).toEqual(1);
done();
}, 100);
});
});
});
describe('when scrolling y-axis', () => {
it('should call `onUpdate`', done => {
const spy = createSpy();
render((
<Scrollbars style={{ width: 100, height: 100 }} onUpdate={spy}>
<div style={{ width: 200, height: 200 }}/>
</Scrollbars>
), node, function callback() {
this.scrollTop(50);
setTimeout(() => {
expect(spy.calls.length).toEqual(1);
done();
}, 100);
});
});
});
describe('when resizing window', () => {
it('should call onUpdate', done => {
const spy = createSpy();
render((
<Scrollbars style={{ width: 100, height: 100 }} onUpdate={spy}>
<div style={{ width: 200, height: 200 }}/>
</Scrollbars>
), node, function callback() {
setTimeout(() => {
expect(spy.calls.length).toEqual(1);
done();
}, 100);
});
});
});
});
}