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

Simple unit test of component using IState<...> #211

Closed
ABIOLI-COM opened this issue Sep 16, 2021 · 5 comments
Closed

Simple unit test of component using IState<...> #211

ABIOLI-COM opened this issue Sep 16, 2021 · 5 comments

Comments

@ABIOLI-COM
Copy link

I cannot write a correct setup for unit testing of a very simple Blazor component using IState<...>.
Anyone with an example? It would be really helpful for everybody, I think.
Thank you.
Andrea

  • Simplified component example (maybe not even working...)
@inherits Fluxor.Blazor.Web.Components.FluxorComponent

@inject IState<string> String_State

<div>
	@String_State.Value
</div>

I would like to write a test that given a state with the content 'something', verifies that the content is correctly generated.

@ABIOLI-COM
Copy link
Author

I came to this code (simplified):

	public class MockStringFeature : Feature<string>
	{
		public override string GetName() => "StringFeature";
		protected override string GetInitialState() => "Something";
	}

Then registering it with:

        ctx.Services.AddSingleton<IState<string>>(
                new Fluxor.State<string>(new MockStringFeature()));

But when running the test it still complains about:

System.InvalidOperationException : Cannot provide a value for property 'ActionSubscriber' on type 'TestComponent'. There is no registered service of type 'Fluxor.IActionSubscriber'.

@AlexTeixeira
Copy link

Hi,

I also have issue with unit testing with my integration tests.

I register Fluxor like ine the Startup.cs :

Services.AddFluxor(options =>
            {
                options.ScanAssemblies(typeof(Startup).Assembly, 
                        AppDomain.CurrentDomain.Load("GenerativePlanting.Shared"),
                        AppDomain.CurrentDomain.Load("GenerativePlanting.Tests"))
                    .UseReduxDevTools();
            });

But when a dispacther method is called, nothing is triggered

@mrpmorris
Copy link
Owner

@ABIOLI-COM did you create your service provider from the Services you registered with?

@AlexTeixeira you probably haven't activated the store. There is a method on IStore, it's usually done by the UI.

@AlexTeixeira
Copy link

@mrpmorris your right, the store was never initialiazed !

@mrpmorris
Copy link
Owner

@ABIOLI-COM I've closed this ticket. Let me know if there is still something unresolved and I will reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants