react-native-modalize
react-native-modalize copied to clipboard
How to unit test this component
Recently I started using this component but found myself not being able to unit test. How to do unit testing with this component
+1
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');
});
});