bUnit is a library that supports unit tests for Blazor components. bUnit builds on top of existing unit testing frameworks (such as NUnit and MSTest), so please make sure that questions asked with this tag focus on the use of bUnit itself.
Questions tagged [bunit]
63 questions
5
votes
1 answer
Blazor test InputDate binding with bUnit
I have a Blazor page and want to do unittesting via bUnit with xUnit.
I want change input value and verify result.
With InputText everything works fine.
With InputNumber I can pass only string. If I pass number value stays the same.
My problem with…

Ivan Ovchinnikov
- 141
- 1
- 7
4
votes
3 answers
How to inject NavigationManager in bunit Blazor component unit test
I am getting this error when injecting from unit test.
System.InvalidOperationException: ''NavigationManagerProxy' has not been initialized.'
My code:
Services.AddSingleton(Mock.Of());

Noor All Safaet
- 438
- 6
- 19
3
votes
1 answer
Mock ProtectedSessionStorage for Blazor
Is there a way to Mock ProtectedSessionStorage in a Blazor Server Side project?
I tried below code but I am getting error : "Type to mock (ProtectedSessionStorage) must be an interface, a delegate, or a non-sealed, non-static class."
private…

harry777
- 61
- 1
- 5
3
votes
1 answer
Is there a way to set the firstRender-Variable of the OnAfterRender method in bunit testing?
Imagine I have the following class and I want to test both, the firstRender = false and the firstRender=true "path". For this sake I am using bunit and xunit.
public class ToTest {
protected async override void OnAfterRender(bool firstRender)
…

3r1c
- 376
- 5
- 20
2
votes
1 answer
Bunit & Blazorise Cannot consume scoped service 'Microsoft.AspNetCore.Components.IComponentActivator' from singleton 'Bunit.Rendering.WebTestRenderer
I am receiving this error to do a unit test with spec test and bunit for a project in Blazor and Blazorise:
Cannot consume scoped service 'Microsoft.AspNetCore.Components.IComponentActivator' from singleton 'Bunit.Rendering.WebTestRenderer
Thi is…

Pikachuuuu
- 95
- 7
2
votes
0 answers
How to do a view unit test for ?
I am working a balzor webassembly project,
I tried to write a unit test for by using Bunit, Xunit,and Moq

hanushi
- 1,169
- 2
- 12
- 27
2
votes
0 answers
Can we do unit testing controllers in Blazor WebAssembly using Bunit
Can we do unit testing for controllers/end point in Blazor WebAssembly using Bunit x unit?
https://bunit.dev/
like this
https://learn.microsoft.com/en-us/aspnet/web-api/overview/testing-and-debugging/unit-testing-controllers-in-web-api?
If not what…

hanushi
- 1,169
- 2
- 12
- 27
2
votes
1 answer
Test "disabled" attribute with bUnit
Please see this simplified Blazor component MyComponent:
2
votes
1 answer
Test event handler of InputFile in Blazor component with bUnit
I have a Blazor component like this:
// MyComponent.razor
@code {
internal IBrowserFile? File;
private void LoadImage(InputFileChangeEventArgs args) => File =…

mu88
- 4,156
- 1
- 23
- 47
2
votes
1 answer
bunit wait until OnInitializedAsync finishes before Asserting fields
I have a blazor server component that load its customers into a table, it gets the customers in the OnInitializedAsync method. Is there a way to wait for the OnInitializedAsync to complete?
Component