lundi 26 décembre 2016

Testng component behaviour (click) in React-Native with Jest

Suppose I have this component:

import React, { Component } from 'react';
import { Text, TouchableWithoutFeedback, View } from 'react-native';

class MyComp extends Component {
  onRowPress() {
    this.myCoolFunction();
  }

  myCoolFunction() { 
    console.log('hi'); 
  }

  render() {
    return (
      <TouchableWithoutFeedback onPress={this.onRowPress.bind(this)}>
        <View>
          <Text>Hello World</Text>
        </View>
      </TouchableWithoutFeedback>
    );
  }
}

export default MyComp;

How do I go about simulating 1 click on the 'TouchableWithoutFeedback' and making sure that 'myCoolFunction' was called exactly 1 times?

If it's not a must, then I would prefer to not add more dependencies other than 'react-dom' and 'react-addons-test-utils'.

I saw a lot of guides claiming this and that but I fear they are outdated and I want to be sure that I'm not going through some unneeded workarounds and bloating my code.

I have jest/react/react native in their latest versions.

Aucun commentaire:

Enregistrer un commentaire