RealOrangeOne / react-native-mock

A fully mocked and test-friendly version of react native (maintainers wanted)
MIT License
571 stars 153 forks source link

Touchable mocks #8

Closed iyawnis closed 8 years ago

iyawnis commented 8 years ago

Using this library, is it possible to simulate touch events, for example clicking on a TouchableHighlight ? I am making use of enzyme with mocha and chain, but not sure how to approach this.

Here is an example of what I am trying:

<Component>
  <View>
    <TouchableHighlight onPress={this.props.buttonPressed}>
      <Text>{this.props.text}</Hello>
    </TouchableHighlight>
  </View>
</Component>
  it('should be pressed', () => {
    let buttonPressed = sinon.spy();
    let wrapper = shallow(<Component text={'Hello'} onPress={buttonPressed} />);
    wrapper.children().forEach( n => {
        n.simulate('click')});
    expect(onButtonClick.calledOnce).to.equal(true);
  });
lelandrichardson commented 8 years ago

@latusaki you should try simulating press instead of click. I believe this should work. Let me know if not!

iyawnis commented 8 years ago

:ohgodwhy:

Yes it is working, did not think that. :+1: