bUnit-dev / bUnit

bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
https://bunit.dev
MIT License
1.14k stars 105 forks source link

Bunit should run tests with component which do constructor injection #1578

Closed beauchama closed 2 weeks ago

beauchama commented 2 weeks ago

Is the feature request related to a problem? Please elaborate.

Hello! I encounter a problem with Bunit which can't run tests because the component inject services from the constructor. The constructor injection is a new feature for Blazor from .NET 9.0. I consider is not a bug because Bunit doesn't use this new approach and it is normal!

I understand that at this moment .NET 9.0 is not ready (release canditate 2) but it will be ready in november. I just wanted to put a trace. It will be nice that Bunit can run tests with this new feature :D

It is not a big problem because I can use the [Inject] attribute.

Additional context Here how it is used the constructor injection. It is same thing if we use the Inject attribute image

The error from the test image

egil commented 2 weeks ago

Yeah, we need to ensure we have support for this. Should be a straightforward fix, but something we need to prioritize. Thanks for putting this on our radar.

@linkdotnet lets put this on the todo list for next fridays "bUnit dev sesions" stream.

linkdotnet commented 2 weeks ago

Sure - hopefully it is straightforward and you can finally tackle the TS->C# stuff :D

linkdotnet commented 2 weeks ago

I fiddled around and the fix is indeed straightforward.