-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Easier handling of triggering stub events
- Loading branch information
1 parent
f8f23e8
commit eebcb86
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/bunit.web/Extensions/RenderedComponentStubExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#if NET5_0_OR_GREATER | ||
using System.Linq.Expressions; | ||
using Bunit.TestDoubles; | ||
|
||
namespace Bunit; | ||
|
||
/// <summary> | ||
/// Extension methods for using component doubles. | ||
/// </summary> | ||
public static class RenderedComponentStubExtensions | ||
{ | ||
/// <summary> | ||
/// Invokes the event callback from the stub. | ||
/// </summary> | ||
public static Task InvokeEventCallback<TComponent>(this IRenderedComponent<Stub<TComponent>> component, | ||
Expression<Func<TComponent, EventCallback>> selector) where TComponent : IComponent | ||
{ | ||
if (component is null) | ||
throw new ArgumentNullException(nameof(component)); | ||
|
||
return component.Instance.InvokeEventCallback(selector); | ||
} | ||
|
||
/// <summary> | ||
/// Invokes the event callback from the stub. | ||
/// </summary> | ||
public static Task InvokeEventCallback<TComponent, TU>(this IRenderedComponent<Stub<TComponent>> component, | ||
Expression<Func<TComponent, EventCallback<TU>>> selector, TU value) where TComponent : IComponent | ||
{ | ||
if (component is null) | ||
throw new ArgumentNullException(nameof(component)); | ||
|
||
return component.Instance.InvokeEventCallback(selector, value); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/bunit.testassets/SampleComponents/DisposeComponents/DisplayInput.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p>User wrote: @value</p> | ||
<InputText @bind-Value="value" /> | ||
@code { | ||
private string value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters