2022-04-07 12:52:57 +00:00
|
|
|
import { cleanupGlobals, setupDOM } from './helpers';
|
|
|
|
import { onReady } from '../src/helpers/ready';
|
|
|
|
|
|
|
|
describe('Testing onReady callback', () => {
|
|
|
|
afterEach(cleanupGlobals);
|
|
|
|
|
2022-09-07 19:11:48 +00:00
|
|
|
it('Testing onReady before DOM is loaded', () => {
|
|
|
|
return new Promise((fulfill) => {
|
|
|
|
setupDOM('');
|
|
|
|
expect(document.readyState).toBe('loading');
|
|
|
|
onReady(() => {
|
|
|
|
fulfill(true);
|
|
|
|
});
|
2022-04-07 12:52:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-07 19:11:48 +00:00
|
|
|
it('Testing onReady after DOM is loaded', () => {
|
|
|
|
return new Promise((fulfill) => {
|
|
|
|
setupDOM('');
|
|
|
|
expect(document.readyState).toBe('loading');
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
expect(document.readyState).toBe('interactive');
|
|
|
|
onReady(() => {
|
|
|
|
fulfill(true);
|
|
|
|
});
|
2022-04-07 12:52:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|