Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions StarButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const propTypes = {
activeOpacity: PropTypes.number.isRequired,
starStyle: ViewPropTypes.style,
onStarButtonPress: PropTypes.func.isRequired,
testID: PropTypes.string,
};

const defaultProps = {
Expand Down Expand Up @@ -151,6 +152,7 @@ class StarButton extends Component {
activeOpacity,
buttonStyle,
disabled,
testID,
} = this.props;

return (
Expand All @@ -159,6 +161,7 @@ class StarButton extends Component {
disabled={disabled}
containerStyle={buttonStyle}
onPress={this.onButtonPress}
testID={testID}
>
{this.renderIcon()}
</Button>
Expand Down
3 changes: 3 additions & 0 deletions StarRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class StarRating extends Component {
}
}

const testID = `star-${i}`

const starButtonElement = (
<AnimatableView
key={i}
Expand All @@ -168,6 +170,7 @@ class StarRating extends Component {
starIconName={starIconName}
starSize={starSize}
starStyle={starStyle}
testID={testID}
/>
</AnimatableView>
);
Expand Down
10 changes: 10 additions & 0 deletions tests/StarButton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const baseProps = {
starSize: 40,
activeOpacity: 0.2,
onStarButtonPress: () => {},
testID: 'star-0',
};

const getMock = (props = {}) => {
Expand All @@ -31,4 +32,13 @@ describe('StarButton component', () => {

expect(rendered).toBeTruthy();
});

it('renders with testID', () => {
const rendered = renderer.create(getMock())

// NOTE: https://github.com/facebook/react-native/issues/16281
const elements = rendered.root.findAll(el => el.props.testID === baseProps.testID && el.type === 'View')

expect(elements.length).toEqual(1);
});
});