import React from 'react'; import { fireEvent, render } from '@testing-library/react-native'; import BottomButton from '../BottomButton'; import noop from '../../helpers/noop'; jest.mock('react-native/Libraries/Components/Keyboard/Keyboard', () => ({ addListener: jest.fn(), dismiss: jest.fn(), })); describe('BottomButton', () => { it.each` element ${()} ${()} ${()} ${()} ${()} `('renders correctly', ({ element }) => { const { toJSON } = render(element); expect(toJSON()).toMatchSnapshot(); }); it('should feedback when users press', done => { const callback = jest.fn(); const { getByText, unmount } = render(); setTimeout(() => { const button = getByText('Tap here'); fireEvent.press(button); expect(callback).toBeCalledTimes(1); done(); }, 1000); }); it('should not feedback when disabled', done => { const callback = jest.fn(); const { getByText, toJSON } = render(); setTimeout(() => { expect(toJSON()).toMatchSnapshot(); done(); }, 1000); }); });