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

Add the possibility to set testID to create unit tests #55

Open
ManuViola77 opened this issue Oct 19, 2021 · 0 comments
Open

Add the possibility to set testID to create unit tests #55

ManuViola77 opened this issue Oct 19, 2021 · 0 comments

Comments

@ManuViola77
Copy link

ManuViola77 commented Oct 19, 2021

In my project, we are writing unit tests for our components and screens and we got stuck for a while because this library doesn't accept the testID property for the main View.

I suggest to add the testID here:

return (
    <View style={[styles.container, containerStyle]} onLayout={this.onLayout} testID={this.props.testID}>
        {this.renderPages(props)}

        <Pager />
      </View>
    );

I think it would be great if you could add the ability to set a testID. If you want I can make the PR, I even tested it locally but I decided to go with a workaround, in case anyone else wants it, here is my current code:

<View testID={'pagesViewWrapperTestId'}>
   <Pages
    ...        
   </Pages>
</View>

And in my test I do:

const pagesViewWrapper = queryByTestId('pagesViewWrapperTestId');
expect(pagesViewWrapper).toBeTruthy();
const pagesView = pagesViewWrapper.children[0].children[0]; // this gets the view from Pages I want to add the testID to access directly to it
fireEvent(pagesView, 'layout', {
	  nativeEvent: { layout: { height: 100 } },
});

The last part is to trigger the onLayout function from the View, otherwise, it doesn't render the pages content.

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

1 participant