-
-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
PortalHost doesn't work in jest render
Description
I have a Dropdown in my app that I want to test, but I'm stuck on an issue: When I click the dropdown button, the expanded is true, but I don't see the menu items in the tests. So I created this basic example to verify the issue. Usually, I have it in the test-utils where I define all of my providers, it's a replica of my root _layout.
Reproduction
import { render, fireEvent, waitFor } from '@testing-library/react-native'
import { PortalHost } from '@rn-primitives/portal'
import { Button } from '~/components/ui/button'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '~/components/ui/dropdown-menu'
import { Text } from '~/components/ui/text'
const TestDropdownComponent = () => {
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button>
<Text>Open Menu</Text>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<Text>Item 1</Text>
</DropdownMenuItem>
<DropdownMenuItem>
<Text>Item 2</Text>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<PortalHost />
</>
)
}
describe('Portal Dropdown Test', () => {
it('should render dropdown content', async () => {
const screen = render(<TestDropdownComponent />)
const trigger = screen.getByText('Open Menu')
fireEvent.press(trigger)
screen.debug()
await waitFor(() => {
expect(screen.getByText('Item 1')).toBeTruthy()
expect(screen.getByText('Item 2')).toBeTruthy()
})
})
})
Screen debug result
● Portal Dropdown Test › should render dropdown content
Unable to find an element with text: Item 1
<View>
<View
accessibilityState={
{
"disabled": false,
"expanded": true, ----> //this is `true`
}
}
accessible={true}
role="button"
>
<Text>
Open Menu
</Text>
</View>
</View>
48 | screen.debug()
jake-carpenter and wildseansy
Metadata
Metadata
Assignees
Labels
No labels