within function Queries

WithinQueries within(
  1. Node node

Takes a DOM node and binds it to the raw query functions.

Can also be used to query within the ShadowRoot of an element by setting node to the Element.shadowRoot value as shown below:

// Or whatever query you want to use to find element(s) within the shadowRoot.
final fooNodeWithinShadowDom = within(someElement.shadowRoot).getByText('foo');

See: testing-library.com/docs/dom-testing-library/api-within


WithinQueries within(Node node) {
  if (node == null) {
    throw ArgumentError.notNull('node');

  if (node is! ShadowRoot && !isOrContains(document.body, node)) {
    throw ArgumentError.value(
        'The element you provide as the single argument to within() must exist in the DOM. '
            'Did you forget to append the element to the body?');

  return WithinQueries._(node);