mercredi 11 mars 2020

How to make test identificator work with FlowJS and React-Native

I am using Flow JS with react-native and my components have data-testid properties for test purposes.

<TouchableOpacity data-testid="touchableOpacityTestId">
  ...
</TouchableOpacity>

And when I run Flow I get multiple errors like "Cannot create TouchableOpacity with data-testid because data-testid is missing in TouchableOpacity". Test itself works ok. I also tried it with testID - no errors then, BUT in this case for some reason enzyme finds a lot of nodes (this testID is absolutely unique and exists only for one node).

const touchableOpacity = wrapper.find({ testID: 'touchableOpacityTestId' });
touchableOpacity.props().onPress(); // fails here cause there are lots of nodes now

And I get this error: Method “props” is meant to be run on 1 node. 4 found instead.. If I replace testID with data-test or any other name it works fine, except that flow fails.

What is recommended way to handle it? According to React Testing Recipes we should use data-customAttr for testing purposes, but it looks like Flow does not now about it.

Aucun commentaire:

Enregistrer un commentaire