Skip to content

Commit 9970365

Browse files
committed
fix: use options interface that includes selector for extend queries
1 parent 16a7eac commit 9970365

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/typedefs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ interface IQueryMethods {
4848
}
4949

5050
type IScopedQueryMethods = {
51-
[K in keyof IQueryMethods]: (m: Matcher, opts?: MatcherOptions) => ReturnType<IQueryMethods[K]>
51+
[K in keyof IQueryMethods]: (
52+
m: Matcher,
53+
opts?: Parameters<IQueryMethods[K]>[2],
54+
) => ReturnType<IQueryMethods[K]>
5255
}
5356

5457
export interface IScopedQueryUtils extends IScopedQueryMethods {

test/extend.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ describe('lib/extend.ts', () => {
8080
expect(text).toEqual(['Hello h1', 'Hello h2', 'Hello h3'])
8181
})
8282

83+
it('should handle the queryAll* methods with a selector', async () => {
84+
const elements = await document.queryAllByText(/Hello/, {selector: 'h2'})
85+
expect(elements).toHaveLength(1)
86+
87+
const text = await page.evaluate(el => el.textContent, elements[0])
88+
89+
expect(text).toEqual('Hello h2')
90+
})
91+
92+
it('should handle the getBy* methods with a selector', async () => {
93+
const element = await document.getByText(/Hello/, {selector: 'h2'})
94+
95+
const text = await page.evaluate(el => el.textContent, element)
96+
97+
expect(text).toEqual('Hello h2')
98+
})
99+
83100
it('should scope results to element', async () => {
84101
const scope = await document.$('#scoped')
85102
const element = await scope!.queryByText(/Hello/)

0 commit comments

Comments
 (0)