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) => {
|
(attributeName: string) => (rendered: RenderResult) => {
|
||||||
const dataAttribute = `data-${attributeName}-test`;
|
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 =
|
export const getSingleElement =
|
||||||
@ -29,9 +34,7 @@ export const getSingleElement =
|
|||||||
const element = querySingleElement(attributeName, attributeValue)(rendered);
|
const element = querySingleElement(attributeName, attributeValue)(rendered);
|
||||||
|
|
||||||
if (!element) {
|
if (!element) {
|
||||||
const validValues = queryAllElements(attributeName)(rendered).map(
|
const validValues = queryAllElements(attributeName)(rendered).attributeValues;
|
||||||
(elem) => elem.getAttribute(dataAttribute),
|
|
||||||
);
|
|
||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Couldn't find HTML element with attribute "${dataAttribute}" with value "${attributeValue}". Valid values are:\n\n"${validValues.join(
|
`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