Root-App / react-native-mock-render

a fork of react-native-mock that renders
MIT License
85 stars 50 forks source link

How to test disabled property? #59

Closed Victorien-Tardif closed 6 years ago

Victorien-Tardif commented 6 years ago

I'd like to test if my <TouchableOpacity /> is actually disabled but I don't know how. I'm aware of how to test props but in case of a "disabled" prop, I don't really want to test if the prop is passed but if the button is actually disabled.

How could I do that?

With a React component I would do

const wrapper = mount(
  <Button disabled>
    Title
  </Button>,
);
expect(
  wrapper
    .find('button')
    .getDOMNode()
    .disabled,
).to.be.true;

but I can't find a way to test a react-native component.

Thanks!

Quadriphobs1 commented 6 years ago

This thread explains how to disabled to <TouchableOpacity /> https://stackoverflow.com/questions/33407665/disabling-buttons-on-react-native

and you can use wrapper.find('TouchableOpacity').props().disabled

Victorien-Tardif commented 6 years ago

Ok thanks, I wondered if there was a way to test if the button is actually disabled and not only if it has the prop disabled but I guess this is not my job but React-Native job to test that :) As long as the <TouchableOpacity /> has prop disabled I think I can be confident with the fact it is disabled :)