react-native-modalize icon indicating copy to clipboard operation
react-native-modalize copied to clipboard

How to unit test this component

Open b2bking opened this issue 3 years ago • 2 comments

Recently I started using this component but found myself not being able to unit test. How to do unit testing with this component

b2bking avatar Sep 29 '21 22:09 b2bking

+1

shubhanus avatar Mar 07 '22 09:03 shubhanus

it('should render the screen without any crashing', async () => {
    const ref = createRef();
    const {getByText} = renderModalize(...)
    // Check if modal is close
    expect(() => getByText('TEXT')).toThrow('Unable to find an element with text: TEXT');

    act(() => {
      ref.current?.open();
    });

    await waitFor(() => {
      // Modalize is open
      expect(() => getByText('TEXT')).toBeDefined();
    });

    act(() => {
      ref.current?.close();
    });

    await waitFor(() => {
      // Modalize is close
      expect(() => getByText('TEXT')).toThrow('Unable to find an element with text: TEXT');
    });
  });

christhoval06 avatar Apr 05 '22 03:04 christhoval06