Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComponentFactories doesn't work if registering AddSyncfusionBlazor on services #1129

Closed
BenSchoen opened this issue Jun 27, 2023 · 3 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@BenSchoen
Copy link

Hello

Thanks for creating this awesome library. I found a little issue:

I have a Component1 with a SfButton and a Component2 inside. I try to stub the Component2, but the button i would use, because i want to test some functionality with him. Therefore i have to call AddSyncfusionBlazor to register the services. If i do that the ComponentFactories.AddStub has no effect anymore....

Is there a work around to add the Syncfusion components and using the ComponentsFactroy together?

I have created a little project to demonstrate the issue in two tests:
TestBunitComponentFactories.zip

Regards
Benny

@linkdotnet
Copy link
Collaborator

linkdotnet commented Jun 27, 2023

I don't have a fix per se, but the root cause: This line AddSyncfusionBlazor does the following:

services.Replace(ServiceDescriptor.Singleton<IComponentActivator, SfComponentActivator>());

That interferes with how the ComponentFactories work:

// This is taken from the Bunit TestContextBase
Services.AddSingleton<IComponentActivator>(new BunitComponentActivator(ComponentFactories));

So essentially "our" activator gets replaced with SyncFusions one.

I am not sure why SyncFusion overrides the activator. But maybe something where we (@egil) have to add an extension point for 3rd party libraries so they can safely add their behavior without breaking the internals of bunit.

@egil
Copy link
Member

egil commented Jun 27, 2023

Ahh, yeah, remember thinking about this scenario of multiple IComponentActivator's competing.

We could change our implementation such that the BunitComponentActivator is instantiated in the TestRenderer and any other IComponentActivator registered in the service collection as input. It would then fall back to using that or to the default Blazor ComponnetActivator. That may be a good idea regardless, since the Blazor team may update theirs.

@egil egil self-assigned this Jul 1, 2023
@egil egil added bug Something isn't working enhancement New feature or request labels Jul 1, 2023
@egil
Copy link
Member

egil commented Jul 2, 2023

Fixed. There should be a release out in a few minutes.

@egil egil closed this as completed Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants