/** * External dependencies */ import type { MatcherFunction } from '@testing-library/react'; /** * This function will match text over several elements, the standard matcher * will only find strings if they are within the same element. */ export const textContentMatcher = ( text: string ): MatcherFunction => { return ( _content, node ) => { const hasText = ( _node ) => _node.textContent === text; const nodeHasText = hasText( node ); const childrenDontHaveText = Array.from( node?.children || [] ).every( ( child ) => ! hasText( child ) ); return nodeHasText && childrenDontHaveText; }; }; /** * This will check if the text is present an the container, it can be within * multiple elements, for example: *