Skip to content

Commit

Permalink
Add prepareContainer option to mount function
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Dec 2, 2024
1 parent 5a14b53 commit e1e6f6b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand All @@ -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 });
Expand Down

0 comments on commit e1e6f6b

Please sign in to comment.