excludesClasses function Matchers

Matcher excludesClasses(
  1. dynamic classes
)

Allows you to check whether an Element does not have certain classes within its HTML class attribute.

classes can be a String of space-separated CSS classes, or an Iterable of String CSS classes.

Similar to using .not.hasClasses(classes) in the jest-dom JS API.

Examples

<button class="btn extra btn-danger">Delete</button>
import 'package:react/react.dart' as react;
import 'package:react_testing_library/matchers.dart' show excludesClasses;
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.button({'className': 'btn extra btn-danger'},
        'Delete',
      ),
    );

    // Use react_testing_library queries to store references to the node(s)
    final deleteButton = view.getByRole('button', name: 'Delete');

    // Use the `excludesClasses` matcher as the second argument of `expect()`
    expect(deleteButton, excludesClasses('not-there'));
    expect(deleteButton, excludesClasses(['not-there', 'nope']));
  });
}

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 the react_testing_library does not have a direct dependency on over_react - but both libraries are fully supported.

Implementation

Matcher excludesClasses(dynamic classes) => _ElementClassNameMatcher(_ClassNameMatcher.unexpected(classes));