Feature
N/A
Generic map function that allows you to map over a Selector. This could be useful with creating assertions that deal with predefined/ expected lists vs actual lists created by the DOM. Since there is already a .filter function, and people always talk about map/filter/reduce being together, this seems like a natural addition to the Selector API.
N/A
Tested page URL:
Test code
Selector('li').map((element) => element.innerText);
Hi @dv297,
Thanks for you proposal, it sounds reasonable.
We need to know what will be returned by Selector methods (a DOM node or something else). Obviously, we can't determine it in case of the map function.
To implement these methods, we would have to rethink the internal Selector methods mechanism.
We'll discuss the possibility to do this in the future.
As a workaround, you can create a ClientFunction, e.g.:
const getInnerTextArr = ClientFunciton((selector) => {
return document.querySelectorAll(selector).map(el => el.innerText);
});
test('Test', async t => {
await t.expect(getInnerTextArr('li')).eql(...);
});
/cc @AlexanderMoskovkin
The suggested code won't work because NodeList does not support "map"
const getInnerTextArr = ClientFunction( function ( selector ) {
const values = []
const elements = document.querySelectorAll( selector )
for ( let i = 0; i < elements.length; i++ ) {
values.push( elements[ i ].textContent )
}
return values
} )
This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.
We're closing this issue after a prolonged period of inactivity. If it still affects you, please create a new issue with up-to-date information. Thank you.
Most helpful comment
The suggested code won't work because NodeList does not support "map"