Skip to content

MudPopoverProvider Required For Components With MudSelect Unit Testing But Causes Runtime Error #5285

@PlayerModu

Description

@PlayerModu

Bug type

Component

Component name

MudPopoverProvider

What happened?

We have a MudDialog component which contains, among other inputs, a MudSelect to allow the user to select from a dropdown list. This is working fine at runtime if we just include MudThemeProvider in the MainLayour.razor.

However, when we try to unit test our component containing the MudSelect, we are not seeing any option items rendered for selection unless we include MudPopoverProvider in the component under test itself. By including this provider, this allows the unit tests to pass but at runtime we see this error in the console:

"System.InvalidOperationException: Duplicate MudPopoverProvider detected. Please ensure there is only one provider, or disable this warning with PopoverOptions.ThrowOnDuplicateProvider."

We followed the advice documented in the code itself and error message by setting the PopoverOptions.ThrowOnDuplicateProvider to false during configuration in Program.cs however this seems to have had no effect as we're still seeing the exception at runtime

    builder.Services.AddMudServices(options =>
    {
        options.PopoverOptions.ThrowOnDuplicateProvider = false;
    });

Reproduction:
This can be replicated through the MudBlazor.Docs project itself by simply including the SelectTest2 component (which has the MudPopoverProvider included) in the SelectVariantsExample.razor and setting config.PopoverOptions.ThrowOnDuplicateProvider to false in the TryAddDocsViewServices() method in MudBlazor.Docs.Server.

When the Select docs page is then loaded, there is an exception banner and the console shows the same exception as above.

It looks like the unit tests fake out the components under test as they include the MudPopoverProvider.

Expected behavior

Honestly not sure, could be able to include PopoverProvider in the individual components where a MudSelect component is used but this then doesn't throw a run-time error, even when ThrowOnDuplicate is set to false... this could cause errors though at runtime with multiple providers not tracking properly? Probably really shouldn't need to manually include this MudPopoverProvider at all?

Reproduction link

https://try.mudblazor.com/snippet/GamQEZvKdMUCOwoq

Reproduction steps

  1. Include MudThemeProvider in MainLayout
  2. Use MudSelect in a component with one or more options
  3. Check that MudSelect is working at runtime
  4. Then attempt to unit test the component and try to select an option
  5. Option items aren't for selection in the unit test
  6. Include MudPopoverProvider in the component
  7. Option items are rendered for selection in the unit test
  8. Run the website and see the exception on the page
  9. Attempt to set PopoverOptions Throw to false
  10. Run the website and see the exception on the page

Relevant log output

No response

Version (bug)

6.0.15

Version (working)

No response

What browsers are you seeing the problem on?

Chrome

On what operating system are you experiencing the issue?

Windows

Pull Request

  • I would like to do a Pull Request

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

answeredA discussion has received a complete response

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions