Comments (6)
Hey @allderidge,
this is unfortunately a limitation we can't overcome. The Blazor renderer doesn't await DisposeAsync
, therefore DisposeComponents
isn't blocking until DisposeAsync
is done.
Therefore you have to find other ways of telling whether or not DisposeAsync
is done (in the worst: Task.Delay(10);
).
from bunit.
Yeah, unfortunately, we do not currently have a hook into the Blazor renderere that allows us to await async disposal, as @linkdotnet says.
That said, you can probably test the logic you need to test in isolation by calling DisposeAsync
yourself:
@inherits TestContextWrapper
@code
{
[Test]
public async Task DisposeAsync_Is_Called_When_Disposing_Components()
{
TestContext = new Bunit.TestContext();
TestContext.JSInterop.Mode = JSRuntimeMode.Loose;
var sut = Render(@<Bug />);
var instance = sut.FindComponent<Bug>().Instance;
await instance.DisposeAsync();
// DisposeComponents();
Assert.IsTrue(instance.WasDisposed);
}
}
from bunit.
Thanks, it does looks like there's very little that can be done other than going into a loop which waits and tests for the outcome until some timeout.
I was thinking that these issues could be solved by implementing your own SynchronizationContext used to wait for all spawned tasks to be processed.
from bunit.
We are actively investigating options like that for V2 of bUnit, but it will be hard to do it for V1 (breaking changes etc.
from bunit.
Done by #1415
from bunit.
We implemented the feature on our upcoming v2
of bUnit. Currently, this version is in preview, but if you feel a bit more adventurous, you can try out the latest preview: https://www.nuget.org/packages/bunit/2.0.24-preview
As it is a major version, there are breaking changes. We have a rudimentary Migration Guide: https://github.com/bUnit-dev/bUnit/blob/v2/MIGRATION.md
Every feedback helps us.
Your test from above can now be properly done via: await DisposeComponentsAsync();
from bunit.
Related Issues (20)
- Enable test doubles for (3rd party) components generation HOT 20
- Problems running docs project locally HOT 6
- Docs: search exposes pages that are not in the TOC
- bunit.web has dependency on alpha version of AngleSharp.Css HOT 2
- No way to set value for property with `[SupplyParameterFromQuery]` but not `[Parameter]` HOT 6
- Support for keyed services HOT 5
- Cannot trigger RowSelected eventcallback on SFgrid HOT 3
- `WrapperElementsGenerator` cachable
- IJSUnmarshalledRuntime removed in .NET 9 HOT 2
- FakeNavigationManager registration changed from Singleton to Scoped HOT 7
- bUnit does not set parameters as a result of two-way binding or chained binding when values are updated. HOT 6
- `@formname` attribute always causes an error: System.InvalidOperationException : Invalid element frame type 'NamedEvent' HOT 2
- upgrading bUnit to 1.27.17 results in bunit.web.testcomponents load errors HOT 2
- WASM MSAL Configuration Not Correctly Supported HOT 1
- Async Task in Multiple Tests HOT 8
- Clicking an Anchor Tag does not update NavigationManager HOT 2
- Unable to resolve service for type 'Bunit.Rendering.ITestRenderer' HOT 4
- diff:ignoreChildren does not Ignore Children of a Button HOT 4
- Change in 1.27.12-preview breaks Moq/AutoMock with loose behavior HOT 5
- Documentation: Footer displays placeholders HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bunit.