This repository was archived by the owner on Aug 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 11const replacer = ( _ : string , value : unknown ) => {
22 if ( value instanceof RegExp ) return `__REGEXP ${ value . toString ( ) } `
3+ if ( typeof value === 'function' ) return `__FUNCTION ${ value . toString ( ) } `
34
45 return value
56}
@@ -11,6 +12,11 @@ const reviver = (_: string, value: string) => {
1112 return new RegExp ( match ! [ 1 ] , match ! [ 2 ] || '' )
1213 }
1314
15+ if ( value . toString ( ) . includes ( '__FUNCTION ' ) ) {
16+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
17+ return new Function ( `return (${ value . split ( '__FUNCTION ' ) [ 1 ] } ).apply(this, arguments)` )
18+ }
19+
1420 return value
1521}
1622
Original file line number Diff line number Diff line change @@ -40,6 +40,28 @@ test.describe('lib/fixture.ts (locators)', () => {
4040 expect ( await locator . textContent ( ) ) . toEqual ( 'Hello h1' )
4141 } )
4242
43+ test ( 'supports function style `TextMatch`' , async ( { screen} ) => {
44+ const locator = screen . getByText (
45+ // eslint-disable-next-line prefer-arrow-callback, func-names
46+ function ( content , element ) {
47+ return content . startsWith ( 'Hello' ) && element ?. tagName . toLowerCase ( ) === 'h3'
48+ } ,
49+ )
50+
51+ expect ( locator ) . toBeTruthy ( )
52+ expect ( await locator . textContent ( ) ) . toEqual ( 'Hello h3' )
53+ } )
54+
55+ test ( 'supports arrow function style `TextMatch`' , async ( { screen} ) => {
56+ const locator = screen . getByText (
57+ ( content , element ) =>
58+ content . startsWith ( 'Hello' ) && element ?. tagName . toLowerCase ( ) === 'h3' ,
59+ )
60+
61+ expect ( locator ) . toBeTruthy ( )
62+ expect ( await locator . textContent ( ) ) . toEqual ( 'Hello h3' )
63+ } )
64+
4365 test ( 'should handle the get* methods' , async ( { queries : { getByTestId} } ) => {
4466 const locator = getByTestId ( 'testid-text-input' )
4567
You can’t perform that action at this time.
0 commit comments