isEmptyDomElement top-level constant Matchers
Matcher
const isEmptyDomElement
Allows you to assert whether an element has content or not.
Similar to jest-dom's toBeEmptyDOMElement
matcher.
Examples
<span data-test-id="not-empty"><span data-test-id="empty"></span></span>
import 'package:react/react.dart' as react;
import 'package:react_testing_library/matchers.dart' show isEmptyDomElement;
import 'package:react_testing_library/react_testing_library.dart' as rtl;
import 'package:test/test.dart';
main() {
test('', () {
// Render the DOM shown in the example snippet above
final view = rtl.render(
react.span({'data-test-id': 'not-empty'},
react.span({'data-test-id': 'empty'}),
),
);
// Use the `isEmptyDomElement` matcher as the second argument of `expect()`
expect(view.getByTestId('empty'), isEmptyDomElement);
expect(view.getByTestId('not-empty'), isNot(isEmptyDomElement));
});
}
NOTE:
render()
supports React vDom elements / custom components created using either the
react or over_react packages.
The examples shown here use the
react
package since thereact_testing_library
does not have a direct dependency onover_react
- but both libraries are fully supported.
{@category Matchers}
Implementation
const Matcher isEmptyDomElement = _IsEmptyDomElement();