hasElement function
Matcher
hasElement(})
Matches if rendered HTML contains element(s) matching the CSS selector.
Optional parameters refine the match:
withText: element's text content must contain this stringwithAttribute: the element must have this attributeattributeValue: combined withwithAttribute, the attribute must equal this valuecount: exactly this many elements must match
expect(html, hasElement('h1', withText: 'Hello'));
expect(html, hasElement('.item', count: 3));
expect(html, hasElement('a[href="/about"]'));
expect(html, hasElement('input', withAttribute: 'required'));
expect(html, hasElement('input', withAttribute: 'type', attributeValue: 'email'));
Implementation
Matcher hasElement(String selector, {String? withText, String? withAttribute, String? attributeValue, int? count}) =>
_HasElementMatcher(
selector,
withText: withText,
withAttribute: withAttribute,
attributeValue: attributeValue,
count: count,
);