Skip to content

Commit 2ebe7c8

Browse files
committed
Make deterministic.
1 parent 3983ad0 commit 2ebe7c8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Components/Components/test/NavigationManagerTest.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,14 +888,15 @@ public void OnNotFoundSubscriptionIsTriggeredWhenNotFoundCalled()
888888
}
889889

890890
[Fact]
891-
public void OnNavigateToCallback_WhenThrows_ShouldBeHandledGracefully()
891+
public async Task OnNavigateToCallback_WhenThrows_ShouldBeHandledGracefully()
892892
{
893893
#nullable enable
894894
// Arrange
895895
var baseUri = "scheme://host/";
896896
var uri = "scheme://host/test";
897897
var testNavManager = new TestNavigationManagerWithExceptionHandling(baseUri);
898898
var expectedException = new InvalidOperationException("Test exception from OnNavigateTo");
899+
var tcs = new TaskCompletionSource();
899900

900901
// First test: Initialize with a callback that throws exceptions
901902
testNavManager.Initialize(baseUri, uri, uri => testNavManager.GetErrorHandledTask(ThrowingMethod(uri)));
@@ -907,14 +908,23 @@ public void OnNavigateToCallback_WhenThrows_ShouldBeHandledGracefully()
907908
// Should be null because the exception was handled gracefully
908909
Assert.Null(wrappedException);
909910

911+
await tcs.Task.WaitAsync(Timeout);
912+
910913
// Verify that the exception was logged
911914
Assert.Single(testNavManager.HandledExceptions);
912915
Assert.Same(expectedException, testNavManager.HandledExceptions[0]);
913916

914917
async Task ThrowingMethod(string param)
915918
{
916-
await Task.Yield();
917-
throw expectedException;
919+
try
920+
{
921+
await Task.Yield();
922+
throw expectedException;
923+
}
924+
finally
925+
{
926+
tcs.SetResult();
927+
}
918928
}
919929
#nullable restore
920930
}

0 commit comments

Comments
 (0)