import { MatcherFunction } from '@testing-library/react' type Query = (f: MatcherFunction) => Element | Promise /* Utility function to run testing-library queries over nodes that contain html tags, as in `

this includes some bold text

`. Usage: const getByTextWithMarkup = withMarkup(screen.getByText) getByTextWithMarkup('this includes some bold text') const findByTextWithMarkup = withMarkup(screen.findByText) await findByTextWithMarkup('this includes some bold text') */ const withMarkup = (query: Query) => (text: string): Element | Promise => query((content: string, node: Element | null) => { if (!node) { return false } const hasText = (node: Element) => node.textContent === text const childrenDontHaveText = Array.from(node.children).every( child => !hasText(child as HTMLElement) ) return hasText(node) && childrenDontHaveText }) export default withMarkup