diff --git a/src/components/Button/Button.tsx b/src/components/Button/Button.tsx index 2e4d2cf519..c40a8ea43d 100644 --- a/src/components/Button/Button.tsx +++ b/src/components/Button/Button.tsx @@ -152,7 +152,7 @@ export type Props = $Omit, 'mode'> & { /** * Reference for the touchable */ - touchableRef?: React.RefObject; + touchableRef?: React.Ref>; /** * testID to be used on tests. */ diff --git a/src/components/__tests__/Button.test.tsx b/src/components/__tests__/Button.test.tsx index 8917eaca92..74f61f2224 100644 --- a/src/components/__tests__/Button.test.tsx +++ b/src/components/__tests__/Button.test.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Animated, StyleSheet } from 'react-native'; +import { Animated, StyleSheet, View } from 'react-native'; import { act, fireEvent, render } from '@testing-library/react-native'; import color from 'color'; @@ -218,6 +218,25 @@ it('should execute onPressOut', () => { expect(onPressOutMock).toHaveBeenCalledTimes(1); }); +it('passes the touchable to a callback touchableRef', () => { + const touchableRef = jest.fn< + void, + [React.ComponentRef | null] + >(); + + const { unmount } = render( + + ); + + expect(touchableRef).toHaveBeenLastCalledWith( + expect.objectContaining({ measure: expect.any(Function) }) + ); + unmount(); + expect(touchableRef).toHaveBeenLastCalledWith(null); +}); + describe('button text styles', () => { it('applies uppercase styles if uppercase prop is truthy', () => { const { getByTestId } = render(