How to write interaction test for the modal/overlay/dialog? #21971
-
Some dialog components will append into the last of body tag(for example, material ui/dialog), but the canvasElement is only under #root, so I couldn't test it. Story Code example: export const Dialog: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const emailInput = canvas.getByLabelText('email', {
selector: 'input',
});
},
}; |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
You might want to wrap the document node, like:
|
Beta Was this translation helpful? Give feedback.
-
The best way to handle this is to make sure your modal has an accessible
|
Beta Was this translation helpful? Give feedback.
-
I'm not sure about context, but I encountered the same issue with MUI modals. When I used the // roughly this, env variable comes from Vite, may be different for you
const muiModalDefaultProps = {
...(import.meta.env.STORYBOOK === 'true' && {
container: document.getElementById('storybook-root'),
}),
}; Then, I just |
Beta Was this translation helpful? Give feedback.
The best way to handle this is to make sure your modal has an accessible
role="dialog"
and then usescreen
like this: