Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spacesuitdiver/0b70e417072a918397da93eafafc5a8e to your computer and use it in GitHub Desktop.
Save spacesuitdiver/0b70e417072a918397da93eafafc5a8e to your computer and use it in GitHub Desktop.
it('correctly forwards refs for grabberProps, closeButtonProps, and headlineProps', () => {
// Create refs for each prop
const grabberRef = createRef<View>();
const closeButtonRef = createRef<typeof Pressable>();
const headlineRef = createRef<Text>();
// Render component with refs
const { getByTestId } = render(
<MyComponent
grabberProps={{ ref: grabberRef, testID: 'grabber' }}
closeButtonProps={{ ref: closeButtonRef, testID: 'close-button' }}
headlineProps={{ ref: headlineRef, testID: 'headline' }}
/>
);
// Verify refs are correctly attached
expect(grabberRef.current).not.toBeNull();
expect(closeButtonRef.current).not.toBeNull();
expect(headlineRef.current).not.toBeNull();
// Ensure the refs map to real native nodes
expect(findNodeHandle(grabberRef.current)).not.toBeNull();
expect(findNodeHandle(closeButtonRef.current)).not.toBeNull();
expect(findNodeHandle(headlineRef.current)).not.toBeNull();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment