-
Notifications
You must be signed in to change notification settings - Fork 728
-
Hi,
I have some tests that initially render a rather large DOM. I have been under the assumption that using queries like screen.getBy...
would potentially be slower than queries narrowed down using within
. Should this be the case? I don't seem to notice a difference and actually the within-queries often seem slower. Using within does give a lot nicer error output when the element searched for is not found, but is that the only benefit?
Beta Was this translation helpful? Give feedback.
All reactions
The only thing that happens in within
is we're binding the queries to the element
, so instead of using screen
which will run document.body.querySelectorAll
, we'll run element.querySelectorAll
. I think it will have a performance impact only if the document.body
is really, really big. I believe that within
's purpose is not a performance boost rather than narrowing down the query to a specific area of a page.
Replies: 1 comment
-
The only thing that happens in within
is we're binding the queries to the element
, so instead of using screen
which will run document.body.querySelectorAll
, we'll run element.querySelectorAll
. I think it will have a performance impact only if the document.body
is really, really big. I believe that within
's purpose is not a performance boost rather than narrowing down the query to a specific area of a page.
Beta Was this translation helpful? Give feedback.