Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor Service does not get injected with bUnit

$
0
0

I have a problem with my .NET 8 Blazor bUnit Tests, where I try to get the services injected with the Services.AddSingleton<>() command, because I have an inject @inject CartService CartService, that causes an error, if I try to run the tests without (see bUnit Website as reference).

But it still is not working and throwing an error, that Services does not have a method called AddSingleton(). Does anybody have an idea, what I can do here?

public void ItemsAreShowedOnOverview() {    Services.AddSingleton<CartService>(new CartService());    using var ctx = new TestContext();    var cutOverview = ctx.RenderComponent<Overview>();    cutOverview.Find("p").MarkupMatches("<p>Taktiles Messgerät</p>");}

I tried to run without the Services.AddSingleton<>() but it will not work an throw an error, that the service is not registered.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>