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:
@@ -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 };
|
||||
Reference in New Issue
Block a user