Skip to content

Commit 0fb7d2f

Browse files
committed
fix: Remove flakiness from DisposeComponents test
1 parent 604e98d commit 0fb7d2f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/bunit.core.tests/TestContextBaseTest.net5.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ public void Test0003()
5050
[Fact(DisplayName = "DisposeComponents captures exceptions from DisposeAsync in Renderer.UnhandledException")]
5151
public async Task Test201()
5252
{
53-
RenderComponent<AsyncThrowExceptionComponent>();
53+
var tcs = new TaskCompletionSource();
54+
var expected = new NotSupportedException();
55+
RenderComponent<AsyncThrowExceptionComponent>(
56+
ps => ps.Add(p => p.DisposedTask, tcs.Task));
5457

5558
DisposeComponents();
5659

57-
var exception = await Renderer.UnhandledException;
58-
exception.ShouldBeOfType<NotSupportedException>();
60+
tcs.SetException(expected);
61+
var actual = await Renderer.UnhandledException;
62+
actual.ShouldBeSameAs(expected);
5963
}
6064

6165
[Fact(DisplayName = "DisposeComponents calls DisposeAsync on rendered components")]
@@ -140,10 +144,12 @@ public void Dispose()
140144

141145
private sealed class AsyncThrowExceptionComponent : ComponentBase, IAsyncDisposable
142146
{
147+
[Parameter]
148+
public Task DisposedTask { get; set; }
149+
143150
public async ValueTask DisposeAsync()
144151
{
145-
await Task.Delay(30);
146-
throw new NotSupportedException();
152+
await DisposedTask;
147153
}
148154
}
149155

0 commit comments

Comments
 (0)