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
@inherits TestContext@code{
[Fact]
publicvoidPreventNavigation()
{// Arrangevarcut=Render(@<Navigation/>);
varnavigationManager=Services.GetRequiredService<NavigationManager>();
// Assert we're at the starting UriAssert.Equal(newUri(new(navigationManager.BaseUri), "/original-path").AbsoluteUri, navigationManager.Uri);
// Act -> click the button to navigatevarbutton=cut.Find("#clickable");
button.Click();
// Assert the path remains the original path as navigation was preventedAssert.Equal(newUri(new(navigationManager.BaseUri), "/original-path").AbsoluteUri, navigationManager.Uri);
}}
Expected behavior:
I would have expected the test to pass. But both line #83 and line #95 are setting the Uri property before it checks if navigation should be prevented. The History Stack is correct, but I would have expected the FakeNavigationManager to behave more like the WebAssemblyNavigationManager
Version info:
bUnit version: 1.34.0
.NET Runtime and Blazor version: net7.0 (Mcrosoft.NETCore.App 7.0.20)
Describe the bug
I would love to try submitting a PR if the maintainers agree this should be changed.
In
FakeNavigationManager.NavigateToCore()the Uri is being set regardless of whether or not handlers prevented navigation.Example:
Testing this component:
With this test:
Results in this output:
Expected behavior:
I would have expected the test to pass. But both line #83 and line #95 are setting the
Uriproperty before it checks if navigation should be prevented. TheHistoryStack is correct, but I would have expected theFakeNavigationManagerto behave more like theWebAssemblyNavigationManagerVersion info:
Additional context: