bUnit | testing library for Blazor components | Frontend Framework library

 by   bUnit-dev C# Version: v1.20.8 License: MIT

kandi X-RAY | bUnit Summary

kandi X-RAY | bUnit Summary

bUnit is a C# library typically used in User Interface, Frontend Framework applications. bUnit has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

bUnit is a testing library for Blazor Components. Its goal is to make it easy to write comprehensive, stable unit tests. With bUnit, you can:. bUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, and MSTest, which run the Blazor component tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              bUnit has a medium active ecosystem.
              It has 897 star(s) with 85 fork(s). There are 25 watchers for this library.
              There were 2 major release(s) in the last 12 months.
              There are 34 open issues and 340 have been closed. On average issues are closed in 87 days. There are 2 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of bUnit is v1.20.8

            kandi-Quality Quality

              bUnit has 0 bugs and 0 code smells.

            kandi-Security Security

              bUnit has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              bUnit code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              bUnit is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              bUnit releases are available to install and integrate.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of bUnit
            Get all kandi verified functions for this library.

            bUnit Key Features

            No Key Features are available at this moment for bUnit.

            bUnit Examples and Code Snippets

            No Code Snippets are available at this moment for bUnit.

            Community Discussions

            QUESTION

            .net blazor wasm testing bunit with localization
            Asked 2022-Feb-10 at 13:35

            I'm building a blazor webassembly site and I want to use bunit for testing purpose.

            I run into trouble with components that use localization, I am getting the following error:

            System.InvalidOperationException Cannot provide a value for property 'L' on type 'Path.To.Component'. There is no registered service of type 'Microsoft.Extensions.Localization.IStringLocalizer`1[Path.To.Component]'. at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass7_0.g__Initialize|1(IServiceProvider serviceProvider, IComponent component)

            I already tried to install localization on the test project, but this did not work.

            ...

            ANSWER

            Answered 2022-Feb-10 at 13:35

            QUESTION

            Blazor StateHasChanged and child parameters (`await Task.Run(StateHasChanged);` vs `await InvokeAsync(StateHasChanged);`)
            Asked 2021-Dec-03 at 10:05

            I recently asked a question regarding the difference between await Task.Run(StateHasChanged); and await InvokeAsync(StateHasChanged); in Blazor wasm here.

            The conclusion was that await Task.Run(StateHasChanged); was incorrect and should be avoided; using it would produce the same results as await InvokeAsync(StateHasChanged); however would fall over when threads are available (The accepted answer explains in detail).

            I've updated my codebase to use await InvokeAsync(StateHasChanged);, however I've discovered there is actually a difference in outcome between the two.

            Here's a minimal reproduction of the issue in my application:

            Parent

            ...

            ANSWER

            Answered 2021-Dec-02 at 06:53

            You aren't passing the new value into the Child component. This is one way you could make it work.

            Source https://stackoverflow.com/questions/70193854

            QUESTION

            In Blazor what is the difference between `await Task.Run(StateHasChanged)` and `await InvokeAsync(StateHasChanged)`?
            Asked 2021-Nov-29 at 11:17

            I've recently inherited a Blazor Webassembly application, however have minimal experience with dotnet or Blazor.

            Some of the components use await Task.Run(StateHasChanged) rather than await InvokeAsync(StateHasChanged) and I'm wondering if this is intentional.

            I ask as await Task.Run(StateHasChanged); gives me the following exception when attempting to render the component using bUnit:

            System.InvalidOperationException The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.

            Changing this to await InvokeAsync(StateHasChanged); allows the component to be rendered in bUnit. However, as far as I can tell, the component functions identically when using the application for either await Task.Run(StateHasChanged) or await InvokeAsync(StateHasChanged).

            What is the difference between these two approaches to invoking StateHasChanged?

            ...

            ANSWER

            Answered 2021-Nov-29 at 11:17

            as far as I can tell, the component functions identically ...

            That is correct. Task.Run(job) will run the job on the ThreadPool. In WebAssembly however there are no extra threads and the main (only) thread will have to run this job sooner or later.

            In Blazor Server you do have Threads. Task.Run() will work there, but StateHasChanged() has to run on the main Thread. That means that

            Source https://stackoverflow.com/questions/70118465

            QUESTION

            Why doesn't AutoFixture return injected services when the services are of type object (even though they have an actual type)?
            Asked 2021-Oct-01 at 07:06

            Due to the way that I'm trying to integrate AutoFixture with BUnit to run some Blazor tests, I need to create an IServiceProvider that will have an internal Fixture, and I can inject objects into that fixture to have those same objects returned when AutoFixture is request to create an object of that type.

            My IServiceProvider looks like this

            ...

            ANSWER

            Answered 2021-Oct-01 at 07:06

            The reason why Inject doesn't infer the type of the instance but rather relies on the generic parameter is because it needs to enable scenarios where it is necessary to register values for base types or interfaces fixture.Inject(instance).

            The way Inject works behind the scenes is that it delegates the registration to Register(Func creator) which then delegates it to a fixture.Customize(c => c.FromFactory(creator).OmitAutoProperties()). So you can see how it wouldn't work when you need type inference.

            You could as you said, make registrations one by one, or you could implement your own injection. Note the implementation below is a lighter implementation of the builder that would be normally generated by AutoFixture, and should cover most scenarios. If you find that some features are not working, like seeded requests, you might need a more complete implementation of the injection.

            Source https://stackoverflow.com/questions/69378259

            QUESTION

            How can I have a fallback service provider return a Mock of a type parameter that is not known at compile time
            Asked 2021-Sep-29 at 15:41

            I'm writing a BUnit test for a Razor component that has injected dependencies like this:

            ...

            ANSWER

            Answered 2021-Sep-29 at 15:41

            A fallback service provider added to bUnit's root service provider is invoked if the root service provider cannot resolve a GetService request. With that info in mind, we can use Moq (or another mocking framework) and a little Reflection trickery to create a fallback service provider, which is really just something that implements the IServiceProvider interface, that will use Moq to create a mocked version of a requested service, when its GetService method is called.

            AutoMockingServiceProvider

            This service provider will use Mock to create a mock of a requested service type once, and any subsequent requests will get the same type returned (they are saved in the mockedTypes dictionary).

            The reason for this is that you can retrieve the same mocked instance of a type in both your test and in the component under test, which allows you to configure the mock in your test.

            The GetMockedService extension method below makes it easy to pull out a Mock from the service provider.

            Source https://stackoverflow.com/questions/69362326

            QUESTION

            Bunit 2 way-binding
            Asked 2021-Sep-11 at 09:20

            I have a Search component that implements a debounce timer so it doesn't call ValueChanged (and therefore doesn't update the property tied to it immediately).

            My Issue

            The bUnit test doesn't appear to two way bind my value I am updating.

            Test code ...

            ANSWER

            Answered 2021-Sep-11 at 09:20

            I tried locally on my machine, and the test passed.

            Here is a simplified version of your component, that only calls TimerElapsed_TickAsync one time per value change and not every time the timer runs out (AutoReset defaults to true), and two different ways to write the test that both pass on my machine:

            Source https://stackoverflow.com/questions/69137525

            QUESTION

            How to open a blazored modal with bunit?
            Asked 2021-Jul-28 at 12:48

            I want to test whether a modal opens up or not with bunit. The problem is, that the modal doesn't get rendered. How to open a blazored modal with bunit?

            Modal Creation in my component under test:

            ...

            ANSWER

            Answered 2021-Jul-26 at 18:39

            The problem is that you are not rendering the component that actually does the rendering. Just passing in an IModalService doesn't do it.

            My approach would be to create a mock of IModalService and assert that the expected method on it is called.

            Source https://stackoverflow.com/questions/68531809

            QUESTION

            How to render a razor components with subcomponents without any parameters when functions wants to be passed a renderFragment
            Asked 2021-Jun-27 at 06:12

            I try to use BUnit for component testing in a Blazor server-side project. I am quite new to this and tried to start a real simple setup:

            ...

            ANSWER

            Answered 2021-Jun-27 at 06:09

            QUESTION

            Is there a way to set the firstRender-Variable of the OnAfterRender method in bunit testing?
            Asked 2021-Jun-08 at 13:54

            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.

            ...

            ANSWER

            Answered 2021-Jun-08 at 13:54

            bUnit allows you to perform multiple renders of a component under test. The first render will always have firstRender set to true, and any additional renders will have it set to false, just like the regular Blazor runtime.

            For example:

            Source https://stackoverflow.com/questions/67887198

            QUESTION

            How to add test authorization with inherited TestContext in BUnit?
            Asked 2021-Jun-07 at 11:15

            I have an inherited TestContext in BUnit and I want to add the Testauthorization.

            This doesn't work:

            ...

            ANSWER

            Answered 2021-Jun-07 at 11:15

            Since AddTestAuthorization is an extension method, you need to use this to get to it. Its an unfortunate limitation in the C# language.

            E.g.:

            Source https://stackoverflow.com/questions/67870223

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install bUnit

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/bUnit-dev/bUnit.git

          • CLI

            gh repo clone bUnit-dev/bUnit

          • sshUrl

            git@github.com:bUnit-dev/bUnit.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link