22///
33/// Provides idiomatic Dart wrappers around @testing-library/react for testing
44/// React components with user-centric queries and interactions.
5+ ///
6+ /// - [React Testing Library documentation] (https://testing-library.com/docs/react-testing-library/intro)
57library ;
68
79import 'dart:async' ;
@@ -122,6 +124,8 @@ external JSAny? _reactAct(JSFunction callback);
122124// =============================================================================
123125
124126/// Wrapper around a DOM node providing query and interaction methods.
127+ ///
128+ /// - [About Queries] (https://testing-library.com/docs/queries/about)
125129final class DomNode {
126130 DomNode ._(this ._node);
127131
@@ -190,6 +194,8 @@ final class DomNode {
190194// =============================================================================
191195
192196/// Query methods for finding elements in the rendered output.
197+ ///
198+ /// - [Queries documentation] (https://testing-library.com/docs/queries/about)
193199final class ScreenQuery {
194200 /// Creates a Screen with the given container.
195201 ScreenQuery ._(this ._container);
@@ -441,6 +447,8 @@ final class ScreenQuery {
441447// =============================================================================
442448
443449/// Result of rendering a React component for testing.
450+ ///
451+ /// - [render documentation] (https://testing-library.com/docs/react-testing-library/api#render)
444452final class TestRenderResult extends ScreenQuery {
445453 TestRenderResult ._(this ._root, DomNode container, this ._baseElement)
446454 : super ._(container);
@@ -475,6 +483,8 @@ final class TestRenderResult extends ScreenQuery {
475483// =============================================================================
476484
477485/// Renders a React element into a detached DOM container for testing.
486+ ///
487+ /// - [render documentation] (https://testing-library.com/docs/react-testing-library/api#render)
478488TestRenderResult render (ReactElement element, {JSObject ? container}) {
479489 final baseElement = container ?? _createElement ('div' );
480490 _appendChild (baseElement);
@@ -492,11 +502,17 @@ TestRenderResult render(ReactElement element, {JSObject? container}) {
492502// =============================================================================
493503
494504/// Wraps code that causes React state updates in an act() block.
505+ ///
506+ /// - [act documentation] (https://react.dev/reference/react/act)
507+ /// - [act 允许你在断言之前等待所有挂起的更新完成] (https://zh-hans.react.dev/reference/react/act)
495508void act (void Function () callback) {
496509 _reactAct (callback.toJS);
497510}
498511
499512/// Async version of act for operations that return a Future.
513+ ///
514+ /// - [act documentation] (https://react.dev/reference/react/act)
515+ /// - [act 允许你在断言之前等待所有挂起的更新完成] (https://zh-hans.react.dev/reference/react/act)
500516Future <void > actAsync (Future <void > Function () callback) async {
501517 await callback ();
502518 await Future <void >.delayed (Duration .zero);
@@ -507,6 +523,8 @@ Future<void> actAsync(Future<void> Function() callback) async {
507523// =============================================================================
508524
509525/// Fires a click event on the element.
526+ ///
527+ /// - [fireEvent documentation] (https://testing-library.com/docs/dom-testing-library/api-events)
510528void fireClick (DomNode element, [Map <String , Object ?>? eventInit]) {
511529 act (() {
512530 final event = _createMouseEvent (
@@ -723,6 +741,8 @@ external void _objectDefineProperty(
723741// =============================================================================
724742
725743/// Simulates a user clicking on an element.
744+ ///
745+ /// - [user-event documentation] (https://testing-library.com/docs/user-event/intro)
726746Future <void > userClick (DomNode element) async {
727747 fireMouseDown (element);
728748 fireFocus (element);
@@ -738,6 +758,8 @@ Future<void> userDblClick(DomNode element) async {
738758}
739759
740760/// Simulates a user typing text into an input.
761+ ///
762+ /// - [type documentation] (https://testing-library.com/docs/user-event/utility#type)
741763Future <void > userType (DomNode element, String text) async {
742764 fireFocus (element);
743765 final buffer = StringBuffer (element.value);
@@ -780,6 +802,8 @@ Future<void> userPaste(DomNode element, String text) async {
780802// =============================================================================
781803
782804/// Waits for a condition to be true.
805+ ///
806+ /// - [waitFor documentation] (https://testing-library.com/docs/dom-testing-library/api-async#waitfor)
783807Future <T > waitFor <T >(
784808 T Function () callback, {
785809 Duration timeout = const Duration (seconds: 1 ),
@@ -801,6 +825,8 @@ Future<T> waitFor<T>(
801825}
802826
803827/// Waits for an element to be removed from the DOM.
828+ ///
829+ /// - [waitForElementToBeRemoved documentation] (https://testing-library.com/docs/dom-testing-library/api-async#waitforelementtoberemoved)
804830Future <void > waitForElementToBeRemoved (
805831 DomNode ? Function () callback, {
806832 Duration timeout = const Duration (seconds: 1 ),
0 commit comments