mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-08-06 08:57:38 +00:00
50 lines
914 B
JavaScript
50 lines
914 B
JavaScript
import globalJsdom from 'jsdom-global';
|
|
import { act } from 'react';
|
|
import { createRoot } from 'react-dom/client';
|
|
|
|
let cleanupJsdom;
|
|
|
|
const setupDropdownTestLifecycle = ()=>{
|
|
beforeAll(()=>{
|
|
cleanupJsdom = globalJsdom();
|
|
});
|
|
|
|
afterAll(()=>{
|
|
cleanupJsdom?.();
|
|
});
|
|
|
|
afterEach(()=>{
|
|
document.body.innerHTML = '';
|
|
jest.restoreAllMocks();
|
|
});
|
|
};
|
|
|
|
const renderDropdown = async (element)=>{
|
|
const host = document.createElement('div');
|
|
document.body.appendChild(host);
|
|
const root = createRoot(host);
|
|
|
|
await act(async ()=>{
|
|
root.render(element);
|
|
});
|
|
|
|
return {
|
|
host,
|
|
cleanup : async ()=>{
|
|
await act(async ()=>{
|
|
root.unmount();
|
|
});
|
|
host.remove();
|
|
}
|
|
};
|
|
};
|
|
|
|
const createOpenMenu = ()=>{
|
|
const menu = document.createElement('div');
|
|
menu.className = 'menu-list';
|
|
menu.hidePopover = jest.fn();
|
|
return menu;
|
|
};
|
|
|
|
export { setupDropdownTestLifecycle, renderDropdown, createOpenMenu };
|