Skip to content

How to verify that element has no children (alternatively, render result is null'ish) #1544

@erheron

Description

@erheron

Ask your Question

I have a component which renders null if some data validation check do not pass.
I'd like to test this behavior using RNTL. Question: how do I do this?
For the record, we are using a custom renderWithProviders function, as suggested in Redux docs

I thought about wrapping the element I'm testing in a <View testId="artificial_root_view"> and then somehow verifying that this view has no children. But when I tried to do the following 👇🏻

expect(screen.getByTestId("artificial_root_view").children).toBeNull();

I got the following error:

expect(received).toBeNull()
    Received: [{"_fiber": [FiberNode]}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions