Skip to content

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

@ManuViola77

Description

@ManuViola77

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions