-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
OverlayScrollbarsComponent.test.tsx
55 lines (49 loc) · 1.74 KB
/
OverlayScrollbarsComponent.test.tsx
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
import { describe, test, afterEach, expect, vi } from 'vitest';
import { render, cleanup } from 'solid-testing-library';
import { OverlayScrollbarsComponent } from '~/overlayscrollbars-solid';
const getComputedStyleOriginal = window.getComputedStyle;
vi.stubGlobal(
'getComputedStyle',
vi.fn(function (...args: Parameters<typeof getComputedStyleOriginal>) {
const result: CSSStyleDeclaration = getComputedStyleOriginal.apply(
// @ts-ignore
this,
args
);
const getPropertyValueOriginal = result.getPropertyValue;
result.getPropertyValue = function (prop: string) {
if (prop === 'scrollbar-width' || prop === 'scrollbarWidth') {
return 'none';
}
return getPropertyValueOriginal.call(this, prop);
};
return result;
})
);
describe('OverlayScrollbarsComponent', () => {
afterEach(() => cleanup());
test('body', async () => {
const htmlElement = document.documentElement;
const { unmount } = render(
() => (
<OverlayScrollbarsComponent element="body">
<section id="body" />
</OverlayScrollbarsComponent>
),
{
baseElement: htmlElement,
container: htmlElement,
wrapper: ({ children }) => {
document.body.remove();
return children;
},
}
);
expect(htmlElement).toHaveAttribute('data-overlayscrollbars');
expect(htmlElement.querySelector('body')).toHaveAttribute('data-overlayscrollbars-initialize');
expect(htmlElement.querySelector('body')).not.toBeEmptyDOMElement();
expect(htmlElement.querySelector('body')?.firstElementChild!.tagName).toBe('SECTION');
expect(htmlElement.querySelector('body')?.firstElementChild).toHaveAttribute('id', 'body');
unmount();
});
});