From e1e6f6b8f13e3c7a1567e9e30890f1856b7aa1ae Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 2 Dec 2024 14:33:27 +0100 Subject: [PATCH] Add prepareContainer option to mount function --- src/mount.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mount.ts b/src/mount.ts index f5f8a80..edba3d9 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -11,6 +11,13 @@ export type MountOptions = { * attached to `document.body`. */ connected?: boolean; + + /** + * When `connected` is true, allows to customize the container to which the + * wrapper is connected to. + * Useful to add custom styles and such. + */ + prepareContainer?: (container: HTMLElement) => void; }; /** @@ -19,13 +26,17 @@ export type MountOptions = { * The component can be unmounted by calling `wrapper.unmount()` or by calling * {@link unmountAll} at the end of the test. */ -export function mount(jsx: VNode, { connected = false }: MountOptions = {}) { +export function mount( + jsx: VNode, + { connected = false, prepareContainer }: MountOptions = {}, +) { let wrapper; if (connected) { const container = document.createElement('div'); container.setAttribute('data-enzyme-container', ''); containers.push(container); + prepareContainer?.(container); document.body.append(container); wrapper = enzyme.mount(jsx, { attachTo: container });