You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/site/docs/interaction/index.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,3 +5,8 @@ title: Interacting with a Component Under Test
5
5
6
6
# Interacting with a Component Under Test
7
7
8
+
This section covers the various ways to interact with a component under test, e.g. trigger event handlers. This and more is covered in the following sub sections:
9
+
10
+
-**<xref:trigger-event-handlers>:** This covers how to invoke event handlers bound to elements rendered by a component under test.
11
+
-**<xref:trigger-renders>:** This covers how to manually trigger a render cycle for a component under test.
12
+
-**<xref:awaiting-async-state>:** This covers how to await one or more asynchronous changes to a component under test's state, before continuing the test.
To use these, first find the element in the component under test where the event handler is bound to, this is usually done with the [`Find(string cssSelector)`](xref:Bunit.RenderedFragmentExtensions.Find(Bunit.IRenderedFragment,System.String)) method, and then invoke the event dispatch helper method of choice.
27
+
28
+
The following section demonstrates how.
29
+
30
+
## Invoking an Event Handler on an Element
31
+
32
+
To invoke an event handler on an element, first find the element in the component under test, and then call the desired event dispatch helper method.
33
+
34
+
Let's look at a common example, where a `@onclick` event handler is invoked. The example will use the `<ClickMe>` component listed here:
1. In the arrange step of the test, the `<ClickMe>` component is rendered and the `<button>` element is found using the [`Find(string cssSelector)`](xref:Bunit.RenderedFragmentExtensions.Find(Bunit.IRenderedFragment,System.String)) method.
53
+
2. In the act step of the test, the `<button>`'s click event handler, in this case, the `ClickHandler` event handler method, is invoked in three different ways:
54
+
- The first and second invocation uses the same [`Click`](xref:Bunit.MouseEventDispatchExtensions.Click(AngleSharp.Dom.IElement,System.Int64,System.Double,System.Double,System.Double,System.Double,System.Int64,System.Int64,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.String)) method. It has a number of optional arguments, some of which are passed in the second invocation. If any arguments are provided, they are added to an instance of the `MouseEventArgs` type, which is passed to the event handler, if it has it as an argument.
55
+
- The last invocation uses the [`Click`](xref:Bunit.MouseEventDispatchExtensions.Click(AngleSharp.Dom.IElement,Microsoft.AspNetCore.Components.Web.MouseEventArgs)) method that takes an instance of the `MouseEventArgs` type, which is passed to the event handler, if it has it as an argument.
56
+
57
+
All the event dispatch helper methods has the same two overloads, one that takes a number of optional arguments, and one that takes the event types `EventArgs` type.
0 commit comments