mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make queries in element discovery return matching attribute values for easier testing
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
14ab27288a
commit
e93ac55d1d
@ -18,7 +18,12 @@ export const queryAllElements =
|
||||
(attributeName: string) => (rendered: RenderResult) => {
|
||||
const dataAttribute = `data-${attributeName}-test`;
|
||||
|
||||
return [...rendered.baseElement.querySelectorAll(`[${dataAttribute}]`)];
|
||||
const results = [...rendered.baseElement.querySelectorAll(`[${dataAttribute}]`)];
|
||||
|
||||
return {
|
||||
elements: results,
|
||||
attributeValues: results.map(result => result.getAttribute(dataAttribute)),
|
||||
};
|
||||
};
|
||||
|
||||
export const getSingleElement =
|
||||
@ -29,9 +34,7 @@ export const getSingleElement =
|
||||
const element = querySingleElement(attributeName, attributeValue)(rendered);
|
||||
|
||||
if (!element) {
|
||||
const validValues = queryAllElements(attributeName)(rendered).map(
|
||||
(elem) => elem.getAttribute(dataAttribute),
|
||||
);
|
||||
const validValues = queryAllElements(attributeName)(rendered).attributeValues;
|
||||
|
||||
throw new Error(
|
||||
`Couldn't find HTML element with attribute "${dataAttribute}" with value "${attributeValue}". Valid values are:\n\n"${validValues.join(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user