Skip to content

Commit 1c7dedd

Browse files
committed
Docs: Trigger event handlers
1 parent ee3e5ae commit 1c7dedd

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<button @onclick="ClickHandler">Click ME!</button>
2+
@code
3+
{
4+
void ClickHandler(MouseEventArgs args)
5+
{
6+
// ...
7+
}
8+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@inherits TestComponentBase
2+
3+
<Fixture Test="ClickingButtonWorks">
4+
<ComponentUnderTest>
5+
<ClickMe />
6+
</ComponentUnderTest>
7+
8+
@code
9+
{
10+
void ClickingButtonWorks(Fixture fixture)
11+
{
12+
// Arrange
13+
var cut = fixture.GetComponentUnderTest<ClickMe>();
14+
var buttonElement = cut.Find("button");
15+
16+
// Act
17+
buttonElement.Click();
18+
buttonElement.Click(detail: 3, ctrlKey: true);
19+
buttonElement.Click(new MouseEventArgs());
20+
21+
// Assert
22+
// ...
23+
}
24+
}
25+
</Fixture>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Components.Web;
2+
using Xunit;
3+
using Bunit;
4+
5+
namespace Bunit.Docs.Samples
6+
{
7+
public class ClickMeTest
8+
{
9+
[Fact]
10+
public void ClickingButtonWorks()
11+
{
12+
// Arrange
13+
using var ctx = new TestContext();
14+
var cut = ctx.RenderComponent<ClickMe>();
15+
var buttonElement = cut.Find("button");
16+
17+
// Act
18+
buttonElement.Click();
19+
buttonElement.Click(detail: 3, ctrlKey: true);
20+
buttonElement.Click(new MouseEventArgs());
21+
22+
// Assert
23+
// ...
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)