2016-02-01 11 views
7

मैं this मार्गदर्शिका का उपयोग कर ड्राइव प्रतिक्रिया प्रतिक्रिया देशी कोड का परीक्षण करने की कोशिश कर रहा हूं। प्रतिक्रियाशील देशी प्रतिक्रियाओं द्वारा उथल-पुथल का उपयोग करके उथले प्रतिपादन और परीक्षण को सक्षम करने के लिए ओवरराइड किया जाता है।प्रतिक्रिया मूल में यूनिट परीक्षण स्पर्श घटना

भले ही मैं उथले प्रस्तुत घटक (इसकी उपस्थिति और बच्चों की जांच) का परीक्षण कर सकूं, मैं स्पर्श घटनाओं का परीक्षण करने में असमर्थ हूं।

handleTouch() { 
this.setState({ showDescription: !this.state.showDescription }); 
} 


render() { 
const description = this.state.showDescription ? (<Text style={styles.description}>{this.props.entry.description}</Text>) : null; 
return (
    <TouchableNativeFeedback onPress={() => this.handleTouch()}> 
    <View style={styles.rowContainer}> 
     <View style={styles.row}> 
     </View> 
     {description} 
    </View> 
    </TouchableNativeFeedback> 
) 
} 

मैं अगर TouchableNativeFeedback के स्पर्श पर, description टैग प्रदान की गई है परीक्षण करने के लिए कोशिश कर रहा हूँ। प्रतिक्रिया TestUtilsSimulate प्रदान करता है लेकिन यह काम नहीं करता है।

यह मेरी कल्पना सेटअप है:

beforeEach(function() { 
    profileView = TestUtils.renderIntoDocument(<ProfileEntryView entry={entry}/>); 
    var touchableNativeFeedback = TestUtils.findRenderedComponentWithType(profileView, TouchableNativeFeedback); 
    TestUtils.Simulate.onTouchEnd(touchableNativeFeedback); 
}); 

मैं कैसे UI सहभागिता प्रतिक्रिया देशी के लिए reactjs TestUtils मदद से इसका परीक्षण होगा?

उत्तर

4

क्योंकि ReactTestUtils अनुकरण में onTouchEnd या onPress ईवेंट नहीं है। अधिक कोड from this page के लिए खोज रहे

var touchableNativeFeedback = TestUtils.findRenderedDOMComponentWithClass(profileView, 'TouchableNativeFeedback'); 
TestUtils.Simulate.click(touchableNativeFeedback); 

: के लिए अपने परीक्षण कोड को अद्यतन

const NativeComponent = (type) => { 
    return React.createClass({ 
     render() { 
      var properties = {className: type}; 
      if (typeof this.props.onPress !== 'undefined') { 
       properties.onClick = this.props.onPress; 
      } 
      Object.assign(properties, this.props); 
      return (
       <div {...properties}>{this.props.children}</div> 
      ); 
     } 
}; 
... 
ReactNative.TouchableNativeFeedback = NativeComponent("TouchableNativeFeedback"); 

और: तो आप नकली वस्तु mocks/react-native.js को जोड़ने की जरूरत है।

संबंधित मुद्दे