-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.spec.tsx
49 lines (47 loc) · 1.42 KB
/
loader.spec.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
import {
act,
} from '@testing-library/react';
import React from 'react';
import {
randomString,
} from '../utils';
import {
mountRootComponent,
} from './loader';
describe('loader', () => {
it('should mount root component in "complete" state', async () => {
const resolved = Promise.resolve();
jest.useFakeTimers();
await act(() => {
const className = 'root-' + randomString();
const rootElement = document.createElement('div');
rootElement.classList.add(className);
document.body.append(rootElement);
const Component = <div className={className} />;
mountRootComponent({Component, rootElement});
expect(document.body.querySelector(`.${className}`)).toBeTruthy();
return resolved;
});
});
it('should mount root component in "loading" state', async () => {
const resolved = Promise.resolve();
Object.defineProperty(
document,
'readyState',
{
get() { return 'loading'; }
}
);
jest.useFakeTimers();
await act(() => {
const className = 'root-' + randomString();
const rootElement = document.createElement('div');
rootElement.classList.add(className);
document.body.append(rootElement);
const Component = <div className={className} />;
mountRootComponent({Component, rootElement});
expect(document.body.querySelector(`.${className}`)).toBeTruthy();
return resolved;
});
});
});