Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Blazor.Diagrams/Extensions/JSRuntimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public static async Task UnobserveResizes(this IJSRuntime jsRuntime, ElementRefe
{
// Ignore, JSRuntime was already disconnected
}
catch (TaskCanceledException)
{
// Ignore, Task was canceled
}
}

public static async Task AddDefaultPreventingForWheelHandler(this IJSRuntime jsRuntime, ElementReference element)
Expand Down
25 changes: 25 additions & 0 deletions tests/Blazor.Diagrams.Tests/Components/DiagramCanvasTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Blazor.Diagrams.Components;
using Blazor.Diagrams.Core.Geometry;
using Bunit;
using Microsoft.JSInterop;
using Xunit;

namespace Blazor.Diagrams.Tests.Components
Expand All @@ -24,5 +25,29 @@ public void Behavior_WhenDisposing_ShouldUnsubscribeToResizes()
// Assert
call.VerifyInvoke("ZBlazorDiagrams.unobserve", calledTimes: 1);
}

[Theory]
[MemberData(nameof(ExceptionTestData))]
public async Task DisposeAsync_ShouldCaptureExpectedExceptions(Exception exceptionToThrow)
{
// Arrange
using var ctx = new TestContext();
ctx.JSInterop.Setup<Rectangle>("ZBlazorDiagrams.getBoundingClientRect", _ => true);
ctx.JSInterop.SetupVoid("ZBlazorDiagrams.unobserve", _ => true).SetException(exceptionToThrow);

// Act
var cut = ctx.RenderComponent<DiagramCanvas>(p => p.Add(n => n.BlazorDiagram, new BlazorDiagram()));
var exception = await Record.ExceptionAsync(async () => await cut.Instance.DisposeAsync());

// Assert
Assert.Null(exception);
}

public static IEnumerable<object[]> ExceptionTestData =>
new List<object[]>
{
new object[] { new TaskCanceledException() },
new object[] { new JSDisconnectedException("JSDisconnectedException") }
};
}
}
Loading