Skip to content

Commit 7c4ec82

Browse files
committed
fix: support regex search on raw queries object
1 parent 67106ba commit 7c4ec82

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function createDelegateFor<T = DOMReturnType>(
107107
let argsToForward = args.map(arg => (arg instanceof RegExp ? convertRegExp(arg) : arg))
108108
// Remove the container from the argsToForward since it's always the first argument
109109
if (containerHandle === args[0]) {
110-
argsToForward = args.slice(1)
110+
argsToForward = argsToForward.slice(1)
111111
}
112112

113113
return processHandleFn!({fnName, containerHandle, evaluateFn, argsToForward})

test/index.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ describe('lib/index.ts', () => {
1818
expect(await queries.getNodeText(element)).toEqual('Hello h1')
1919
})
2020

21+
it('should support regex on raw queries object', async () => {
22+
const scope = await page.$('#scoped')
23+
if (!scope) throw new Error('Should have scope')
24+
const element = await queries.getByText(scope, /Hello/i)
25+
expect(await queries.getNodeText(element)).toEqual('Hello h3')
26+
})
27+
2128
it('should bind getQueriesForElement', async () => {
2229
const {getByText} = getQueriesForElement(await getDocument(page))
2330
const element = await getByText('Hello h1')

0 commit comments

Comments
 (0)