Skip to content

Commit 6644a5e

Browse files
authored
fix: Bad elements refetch not passing the this browser context (#2008)
* Fix bad elements refetch not passing the this browser context * code review
1 parent a236cba commit 6644a5e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/util/refetchElements.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export const refetchElements = async (
1212
full = false
1313
): Promise<WdioElements> => {
1414
if (elements && wait > 0 && (elements.length === 0 || full) && isElementArray(elements) && elements.parent && elements.foundWith && elements.foundWith in elements.parent) {
15-
const fetchFunction = elements.parent[elements.foundWith as keyof typeof elements.parent] as Function
16-
elements = await fetchFunction(elements.selector, ...elements.props)
15+
const browser = elements.parent
16+
const $$ = browser[elements.foundWith as keyof typeof browser] as Function
17+
elements = await $$.call(browser, elements.selector, ...elements.props)
1718
}
1819
return elements
1920
}

test/util/refetchElements.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ describe('refetchElements', () => {
5151
const actual = await refetchElements(elements, 0, true)
5252
expect(actual).toEqual(elements)
5353
})
54+
55+
test('should call $$ with all props', async () => {
56+
elements.props = ['prop1', 'prop2']
57+
await refetchElements(elements, 5, true)
58+
expect(elements.parent.$$).toHaveBeenCalledWith('parent', 'prop1', 'prop2')
59+
})
60+
61+
test('should call $$ with the proper parent this context', async () => {
62+
const parentFoundWith = vi.mocked(elements.parent.$$)
63+
64+
await refetchElements(elements, 5, true)
65+
66+
expect(parentFoundWith.mock.contexts[0]).toBe(elements.parent)
67+
})
5468
})
5569

5670
describe('given WebdriverIO.Element[] type', () => {

0 commit comments

Comments
 (0)