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 ;
@@ -27,15 +27,15 @@ public partial class DiagramCanvas : IDisposable
2727
2828 [ Inject ] public IJSRuntime JSRuntime { get ; set ; } = null ! ;
2929
30- public void Dispose ( )
30+ public async ValueTask DisposeAsync ( )
3131 {
3232 BlazorDiagram . Changed -= OnDiagramChanged ;
3333
3434 if ( _reference == null )
3535 return ;
3636
3737 if ( elementReference . Id != null )
38- _ = JSRuntime . UnobserveResizes ( elementReference ) ;
38+ await JSRuntime . UnobserveResizes ( elementReference ) ;
3939
4040 _reference . Dispose ( ) ;
4141 }
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