Kobalte popover not opening in testing

I'm using a Kobalte popover component. It works just fine in the browser, but for some reason it isn't opening in testing:
test("Clicking the button opens the popover", async () => {
const openButton = screen.getByRole("button", { name: "open popover" })
await userEvent.click(openButton)
expect(screen.getByRole("dialog"))
})
test("Clicking the button opens the popover", async () => {
const openButton = screen.getByRole("button", { name: "open popover" })
await userEvent.click(openButton)
expect(screen.getByRole("dialog"))
})
The above fails for not finding a dialog element.
4 Replies
Max
Max2y ago
is userEvent here the export from testing library ? or return from userEvent.setup call some things don't work as exptected if userEvent is not setup before render
Nathan
NathanOP2y ago
Yeah, userEvent is the export. Switching to a return from setup called before rendering didn't change anything. But thanks, I didn't know about that.
Max
Max2y ago
annoying it didnt fix, just to check, that's not full code right? components is getting rendered somewhere
Nathan
NathanOP2y ago
Yes, that's just the individual test

Did you find this page helpful?