Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/util/refetchElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export const refetchElements = async (
full = false
): Promise<WdioElements> => {
if (elements && wait > 0 && (elements.length === 0 || full) && isElementArray(elements) && elements.parent && elements.foundWith && elements.foundWith in elements.parent) {
const fetchFunction = elements.parent[elements.foundWith as keyof typeof elements.parent] as Function
elements = await fetchFunction(elements.selector, ...elements.props)
const browser = elements.parent
const $$ = browser[elements.foundWith as keyof typeof browser] as Function
elements = await $$.call(browser, elements.selector, ...elements.props)
}
return elements
}
14 changes: 14 additions & 0 deletions test/util/refetchElements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ describe('refetchElements', () => {
const actual = await refetchElements(elements, 0, true)
expect(actual).toEqual(elements)
})

test('should call $$ with all props', async () => {
elements.props = ['prop1', 'prop2']
await refetchElements(elements, 5, true)
expect(elements.parent.$$).toHaveBeenCalledWith('parent', 'prop1', 'prop2')
})

test('should call $$ with the proper parent this context', async () => {
const parentFoundWith = vi.mocked(elements.parent.$$)

await refetchElements(elements, 5, true)

expect(parentFoundWith.mock.contexts[0]).toBe(elements.parent)
})
})

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