File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed
src/Blazor.Diagrams/Components
tests/Blazor.Diagrams.Tests/Components Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 88
99namespace Blazor . Diagrams . Components ;
1010
11- public partial class DiagramCanvas : IDisposable
11+ public partial class DiagramCanvas : IAsyncDisposable
1212{
1313 private DotNetObjectReference < DiagramCanvas > ? _reference ;
1414 private bool _shouldRender ;
@@ -28,15 +28,15 @@ public partial class DiagramCanvas : IDisposable
2828
2929 [ Inject ] public IJSRuntime JSRuntime { get ; set ; } = null ! ;
3030
31- public void Dispose ( )
31+ public async ValueTask DisposeAsync ( )
3232 {
3333 BlazorDiagram . Changed -= OnDiagramChanged ;
3434
3535 if ( _reference == null )
3636 return ;
3737
3838 if ( elementReference . Id != null )
39- _ = JSRuntime . UnobserveResizes ( elementReference ) ;
39+ await JSRuntime . UnobserveResizes ( elementReference ) ;
4040
4141 _reference . Dispose ( ) ;
4242 }
Original file line number Diff line number Diff line change 1+ using Blazor . Diagrams . Components ;
2+ using Blazor . Diagrams . Core . Geometry ;
3+ using Bunit ;
4+ using Xunit ;
5+
6+ namespace Blazor . Diagrams . Tests . Components
7+ {
8+ public class DiagramCanvasTests
9+ {
10+ [ Fact ]
11+ public void Behavior_WhenDisposing_ShouldUnsubscribeToResizes ( )
12+ {
13+ // Arrange
14+ JSRuntimeInvocationHandler call ;
15+ using ( var ctx = new TestContext ( ) )
16+ {
17+ ctx . JSInterop . Setup < Rectangle > ( "ZBlazorDiagrams.getBoundingClientRect" , _ => true ) ;
18+ call = ctx . JSInterop . SetupVoid ( "ZBlazorDiagrams.unobserve" , _ => true ) . SetVoidResult ( ) ;
19+
20+ // Act
21+ var cut = ctx . RenderComponent < DiagramCanvas > ( p => p . Add ( n => n . BlazorDiagram , new BlazorDiagram ( ) ) ) ;
22+ }
23+
24+ // Assert
25+ call . VerifyInvoke ( "ZBlazorDiagrams.unobserve" , calledTimes : 1 ) ;
26+ }
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments