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

How to test react-native-collapsible/Accordion using testing-libray/react-native? #467

Open
Shail-Patel-1 opened this issue Jul 3, 2023 · 1 comment

Comments

@Shail-Patel-1
Copy link

 const { getByTestId } = testingHelpers.renderWithProviders(
      <ProductDetailScreen {...testProps} />,
      {
        preloadedState: preloadedState,
      }
    );
    const productSpecificationsTitleView = getByTestId(
      TestIds.PRODUCT_DETAIL.PRODUCT_SPECIFICATION_TITLE
    );

    expect(productSpecificationsTitleView).toBeDefined();

    await act(async () => {
      await fireEvent.press(productSpecificationsTitleView);
    });

    const productSpecificationsContentView = getByTestId(
      TestIds.PRODUCT_DETAIL.PRODUCT_SPECIFICATION_CONTENT
    );

    expect(productSpecificationsContentView).toBeDefined();
  });

Whether or not i press the title the content is still present in the dom

Used & tested:

toBeDefined
toBeOnScreen
toBeNull
toBeVisible

but above all fails
i used queryByTestId, getByTestId, queryByText

@KonstantinKostianytsia
Copy link

I tested on this way

const firstItemCollapsable = screen.getByTestId(
      `${LongformContentNavigationTestIDs.outlineListItemContainer}.${mockedRoutes[0].id}`,
    ).children[1];
    /// is hidden
    expect(firstItemCollapsable.instance.props.collapsed).toBe(true);
    fireEvent.press(firstItemIcon);
    /// is collapsed
    expect(firstItemCollapsable.instance.props.collapsed).toBe(false);
    fireEvent.press(firstItemIcon);
    /// is hidden again
    expect(firstItemCollapsable.instance.props.collapsed).toBe(true);

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

No branches or pull requests

2 participants