-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
I am running into a slightly awkward use case sometimes is where I have something which is stateful and I need to test that it responds correctly to prop changes (e.g. by resetting state or changing the destination of an in-progress animation).
What I've ended up doing so far is using addSceneTest
with a one-off component, all defined inline, that has a form and the component under test in it. e.g.
class ComponentUnderTest extends React.Component {
/* pretend a complicated component with its own componentWillUpdate() method is here */
render() {
const {text} = this.props;
return <Text>{text}</Text>;
}
}
ComponentUnderTest.propTypes = {
text: PropTypes.string.isRequired,
};
class TestScene extends React.Component {
state = {
text: 'initial test value',
}
_onText: text => this.setState({text})
render() {
return (
<View>
<TextInput value={this.state.text} onChangeText={this._onText} />
<ComponentUnderTest text={this.state.text} />
</View>
);
}
}
addSceneTest(() => TestScene, {
name: 'ComponentUnderTest',
title: 'ComponentUnderTest with changeable text prop',
});
Could there be a nicer way of doing this?
benvium
Metadata
Metadata
Assignees
Labels
No labels