Skip to content

Commit c0f1dea

Browse files
linkdotnetegil
authored andcommitted
fix: Set Task as successful when exception should be ignored (Fixes #634)
1 parent 9fba678 commit c0f1dea

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/bunit.core/Rendering/TestRenderer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ public Task DispatchEventAsync(
8282
}
8383
catch (ArgumentException ex) when (string.Equals(ex.Message, $"There is no event handler associated with this event. EventId: '{eventHandlerId}'. (Parameter 'eventHandlerId')", StringComparison.Ordinal))
8484
{
85+
if (ignoreUnknownEventHandlers)
86+
{
87+
return Task.CompletedTask;
88+
}
89+
8590
var betterExceptionMsg = new UnknownEventHandlerIdException(eventHandlerId, fieldInfo, ex);
8691
return Task.FromException(betterExceptionMsg);
8792
}
8893
});
8994

90-
if (result.IsFaulted && result.Exception is not null && !(ignoreUnknownEventHandlers && result.Exception.InnerException is UnknownEventHandlerIdException))
95+
if (result.IsFaulted && result.Exception is not null)
9196
{
9297
HandleException(result.Exception);
9398
}

tests/bunit.web.tests/BlazorE2E/ComponentRenderingTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,4 +598,15 @@ public void CanHandleRemovedParentObjects()
598598
cut.WaitForState(() => !cut.FindAll("div").Any());
599599
cut.FindAll("div").Count.ShouldBe(0);
600600
}
601+
602+
[Fact]
603+
public async Task CanHandleRemovedParentObjectsAsync()
604+
{
605+
var cut = RenderComponent<DispatcherException>();
606+
607+
await cut.Find("button").ClickAsync(new MouseEventArgs());
608+
609+
cut.WaitForState(() => !cut.FindAll("div").Any());
610+
cut.FindAll("div").Count.ShouldBe(0);
611+
}
601612
}

0 commit comments

Comments
 (0)