-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathgetScrollBarSize.test.ts
More file actions
75 lines (63 loc) · 1.62 KB
/
getScrollBarSize.test.ts
File metadata and controls
75 lines (63 loc) · 1.62 KB
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
67
68
69
70
71
72
73
74
75
import getScrollBarSize, {
getTargetScrollBarSize,
} from '../src/getScrollBarSize';
import { spyElementPrototypes } from '../src/test/domHook';
const DEFAULT_SIZE = 16;
describe('getScrollBarSize', () => {
let defaultSize = DEFAULT_SIZE;
beforeAll(() => {
spyElementPrototypes(HTMLElement, {
offsetWidth: {
get: () => {
return 100;
},
},
clientWidth: {
get: () => {
return 100 - defaultSize;
},
},
});
});
beforeEach(() => {
defaultSize = DEFAULT_SIZE;
});
it('basicSize', () => {
expect(getScrollBarSize()).toEqual(16);
});
it('fresh it', () => {
expect(getScrollBarSize(true)).toEqual(16);
defaultSize = 33;
expect(getScrollBarSize(true)).toEqual(33);
});
describe('getTargetScrollBarSize', () => {
it('invalidate', () => {
expect(
getTargetScrollBarSize({ notValidateObject: true } as any),
).toEqual({
width: 0,
height: 0,
});
});
it('should pass csp nonce to updateCSS', () => {
const updateCSSSpy = jest.spyOn(
require('../src/Dom/dynamicCSS'),
'updateCSS',
);
const target = document.createElement('div');
document.body.appendChild(target);
try {
const nonce = 'test-nonce-123';
getTargetScrollBarSize(target, { nonce });
expect(updateCSSSpy).toHaveBeenCalledWith(
expect.any(String),
expect.any(String),
{ csp: { nonce } },
);
} finally {
updateCSSSpy.mockRestore();
document.body.removeChild(target);
}
});
});
});