0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-08-06 06:47:38 +00:00

Move tests to tests/components directory

This commit is contained in:
Gazook89
2026-05-29 15:58:00 -05:00
parent cf8f809eec
commit a3469a172a
4 changed files with 3 additions and 3 deletions
@@ -0,0 +1,49 @@
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 };