Skip to content

Commit

Permalink
feat: support element wrappers that override getValue, getText, isSel…
Browse files Browse the repository at this point in the history
…ected, etc
  • Loading branch information
jedwards1211 committed Apr 28, 2022
1 parent 7976ec5 commit 0884953
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/assertions/count.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const count = (client, chai, utils, options) => {
type: 'count',
getValueAndSelector: async () => {
const [elements, selector] = await getElements(obj, client)
return [elements.length, selector]
return [(await Promise.all(elements)).flat().length, selector]
},
})
}
Expand Down
5 changes: 4 additions & 1 deletion src/assertions/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ const text = (client, chai, utils, options) => {
message: `elements' text for #{selector}`,
getValueAndSelector: async () => {
const [elements, selector] = await getElements(obj, client)
return [await Promise.all(elements.map(e => e.getText())), selector]
return [
(await Promise.all(elements.map(e => e.getText()))).flat(),
selector,
]
},
})
}
Expand Down
5 changes: 4 additions & 1 deletion src/assertions/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ const value = (client, chai, utils, options) => {
message: `elements' values for #{selector}`,
getValueAndSelector: async () => {
const [elements, selector] = await getElements(obj, client)
return [await Promise.all(elements.map(e => e.getValue())), selector]
return [
(await Promise.all(elements.map(e => e.getValue()))).flat(),
selector,
]
},
})
}
Expand Down
7 changes: 5 additions & 2 deletions src/util/getElements.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export default async function getElements(obj, client) {
if (obj && typeof obj.then === 'function') {
const resolved = await obj
if (
obj &&
(typeof obj.isClickable === 'function' || typeof obj.then === 'function')
) {
const resolved = typeof obj.isClickable === 'function' ? obj : await obj
const selector = obj.selector || String(resolved)
if (typeof resolved === 'string') obj = resolved
else if (Array.isArray(resolved)) return [resolved, selector]
Expand Down

0 comments on commit 0884953

Please sign in to comment.