From 0884953f5b5458cdc1e95c7e40bbf8d7a32608d8 Mon Sep 17 00:00:00 2001 From: Andy Edwards <jedwards@fastmail.com> Date: Wed, 27 Apr 2022 20:58:35 -0500 Subject: [PATCH] feat: support element wrappers that override getValue, getText, isSelected, etc --- src/assertions/count.js | 2 +- src/assertions/text.js | 5 ++++- src/assertions/value.js | 5 ++++- src/util/getElements.js | 7 +++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/assertions/count.js b/src/assertions/count.js index 4865cd1..ebe89e3 100644 --- a/src/assertions/count.js +++ b/src/assertions/count.js @@ -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] }, }) } diff --git a/src/assertions/text.js b/src/assertions/text.js index 3fc601b..4e8ce4c 100644 --- a/src/assertions/text.js +++ b/src/assertions/text.js @@ -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, + ] }, }) } diff --git a/src/assertions/value.js b/src/assertions/value.js index 33b4193..7e408da 100644 --- a/src/assertions/value.js +++ b/src/assertions/value.js @@ -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, + ] }, }) } diff --git a/src/util/getElements.js b/src/util/getElements.js index e798ba4..6fa69bc 100644 --- a/src/util/getElements.js +++ b/src/util/getElements.js @@ -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]