Skip to content

Commit 857bac4

Browse files
committed
fix: use options interface that includes selector for extend queries
1 parent c7427b1 commit 857bac4

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
@@ -46,7 +46,10 @@ interface IQueryMethods {
4646
}
4747

4848
type IScopedQueryMethods = {
49-
[K in keyof IQueryMethods]: (m: Matcher, opts?: MatcherOptions) => ReturnType<IQueryMethods[K]>
49+
[K in keyof IQueryMethods]: (
50+
m: Matcher,
51+
opts?: Parameters<IQueryMethods[K]>[2],
52+
) => ReturnType<IQueryMethods[K]>
5053
}
5154

5255
export interface IScopedQueryUtils extends IScopedQueryMethods {

test/extend.test.ts

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

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

0 commit comments

Comments
 (0)