react-native-actions-sheet icon indicating copy to clipboard operation
react-native-actions-sheet copied to clipboard

How can I test the visibility of actionSheet/content?

Open ramos-lucas opened this issue 4 years ago • 3 comments

I'm using @testing-library/react-native to test my app and I noticed that the content of the action sheet is present in the component tree even when it is closed.

Is there a way of testing this?

ramos-lucas avatar May 07 '21 18:05 ramos-lucas

I'm using @testing-library/react-native to test my app and I noticed that the content of the action sheet is present in the component tree even when it is closed.

Is there a way of testing this?

That's normal. Modal works like that. If you don't want it to be in the component tree, you can hide it using state. I think there is a testID prop you can use to give test ID to ActionSheet to test it.

{visible && <ActionSheet>
//.... 
</ActionSheet>}

ammarahm-ed avatar May 07 '21 18:05 ammarahm-ed

Yes, I tried to do that, but I had some problems because the reference is destroyed. I tried something using useEffect / useLayoutEffect and onClose prop, but I started to have some problems with the animation

ramos-lucas avatar May 07 '21 20:05 ramos-lucas

Yes, I tried to do that, but I had some problems because the reference is destroyed. I tried something using useEffect / useLayoutEffect and onClose prop, but I started to have some problems with the animation

Show me how you are doing it. You need to set state then call show after 50 to 100ms using setTimeout.

ammarahm-ed avatar May 08 '21 10:05 ammarahm-ed

v0.8.0 gives several test ids to address this in e2e tests.

ammarahm-ed avatar Aug 21 '22 06:08 ammarahm-ed