-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add prepareContainer option to mount function #59
Conversation
Since we have already agreed on this API, I'll just go ahead and merge it. |
|
||
/** | ||
* When `connected` is true, allows to customize the container to which the | ||
* wrapper is connected to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would phrase this as "allows customizing the DOM container in which the component is mounted".
let wrapper; | ||
if (connected) { | ||
const container = document.createElement('div'); | ||
container.setAttribute('data-enzyme-container', ''); | ||
containers.push(container); | ||
|
||
prepareContainer?.(container); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible we might encounter use cases in future where the callback needs the container to be connected (ie. in the body) when called. This would be necessary to resolved computed styles for example. I haven't seen any existing use cases where this is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I added the call before appending the container to the body, because that was the approach in all places where we were setting styles.
But yeah, it's possible we need to do it the other way around in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noted a hazard with the ordering of operations we might encounter in future and suggested some wording tweaks to the comment.
As discussed in slack, this PR adds a
prepareContainer?: (container: HTMLElement) => void
option to themount
function, which allows to customize the container whenconnect
istrue
.