Skip to content
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

Interaction canvasElement should be set to the iframe body (Interaction Test) #16971

Open
cgat opened this issue Dec 9, 2021 · 4 comments
Open

Comments

@cgat
Copy link

cgat commented Dec 9, 2021

Describe the bug
The canvasElement that gets passed to the play function points to the root div element in the iframe (<div id="root">). However, if you are using createPortal (with a modal, for example), these elements will be appended outside of the root. This can lead to some confusion, as the elements that appears within the portal are not queryable in the typical manner.

To Reproduce
Can provide if deemed necessary.

System
Storybook 6.4.4. React

Additional context

As a work around, you can reference the parent of canvasElement. Perhaps it would be enough to document this.

MyStory.play = async ({canvasElement}) => {
  //@ts-ignore
 const canvas = within(canvasElement.parentElement)
 ....
}
@adrian-amigues
Copy link

I am encountering the same problem.

Thank you for your workaround, but as you show in it, typescript will raise an error as parentElement is typed as HTMLElement | null, so not ideal. But it will work for now.

I'm not sure what the fix could be, maybe the addition of another argument property which encapsulated the portal ? Not sure if it would be possible.

@londonbarrett
Copy link

For me it's not working, even using screen or the workaround mentioned before

@mattlong
Copy link

mattlong commented Jul 15, 2022

My workaround for this is to grab the current document's body element. Typescript is happy with it.

const body = canvasElement.ownerDocument.body;
await expect(
  await within(body).findByText("Text within portal")
)

@Axedyson
Copy link

Thanks @mattlong your workaround works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants