dblClick static method Null safety

void dblClick(
  1. Element element,
  2. {Map eventInit = const {},
  3. bool skipPointerEventsCheck = false}
)

Clicks element twice, depending on what element is it can have different side effects.

See: testing-library.com/docs/ecosystem-user-event/#dblclickelement-eventinit-options

Options

eventInit

Use eventInit to set options on the initial MouseEvent. For example,

UserEvent.dblClick(element, eventInit: {'shiftKey': true});

skipPointerEventsCheck

Attempting to interact with an element that has 'pointer-events: none' set will throw an error. Use skipPointerEventsCheck to prevent that error from being thrown by skipping the check of whether any element in the DOM-tree has 'pointer-events: none' set. In addition, the underlying check for pointer events is costly in general and very costly when rendering large DOM-trees. Can be used to speed up tests.

Example

<input type="checkbox" onChange={() => clickCount++} />
import 'package:react/react.dart' as react;
import 'package:react_testing_library/matchers.dart' show isChecked;
import 'package:react_testing_library/react_testing_library.dart' as rtl;
import 'package:react_testing_library/user_event.dart';
import 'package:test/test.dart';

void main() {
  test('', () {
    var clickCount = 0;

    // Render the DOM shown in the example snippet above.
    final view = rtl.render(react.input({
      'type': 'checkbox',
      'onChange': (_) => clickCount++,
    }));

    // Use react_testing_library queries to store references to the node.
    final checkbox = view.getByRole('checkbox');

    // Use `UserEvent.dblClick` to simulate a user double clicking the checkbox.
    UserEvent.dblClick(checkbox);

    expect(clickCount, equals(2));

    // Use `isChecked` matcher to verify that the checkbox is no longer checked.
    expect(checkbox, isNot(isChecked));
  });
}

Warning About Errors

Unlike the JS API, any uncaught errors thrown during event propagation will get rethrown. This helps surface errors that could otherwise go unnoticed since they aren't printed to the terminal when running tests.

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.

{@category UserActions}

Implementation

static void dblClick(
  Element element, {
  Map eventInit = const {},
  bool skipPointerEventsCheck = false,
}) {
  final options = {
    'skipPointerEventsCheck': skipPointerEventsCheck,
  };

  eventHandlerErrorCatcher(() {
    getProperty(_userEvent, 'dblClick')(
      element,
      _jsifyEventData(eventInit),
      jsifyAndAllowInterop(options),
    );
  });
}