Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 27 15:10
    dnfadmin commented #542
  • Oct 27 15:10
    dnfadmin commented #541
  • Oct 27 15:10
    dependabot[bot] labeled #542
  • Oct 27 15:10
    dependabot[bot] opened #542
  • Oct 27 15:10
    dependabot[bot] labeled #541
  • Oct 27 15:10
    dependabot[bot] opened #541
  • Oct 25 15:09
    dnfadmin commented #537
  • Oct 25 15:09
    dependabot[bot] labeled #537
  • Oct 25 15:09
    dependabot[bot] opened #537
  • Oct 25 13:50
    egil closed #535
  • Oct 25 13:50
    egil locked #535
  • Oct 25 13:50
    egil commented #535
  • Oct 25 13:27
    drma-dev opened #535
  • Oct 23 16:31
    egil commented #529
  • Oct 23 16:27
    egil labeled #532
  • Oct 23 16:27
    egil opened #532
  • Oct 23 16:24
    egil closed #529
  • Oct 23 16:24
    egil commented #529
  • Oct 23 15:41
    egil closed #528
  • Oct 23 15:41
    egil locked #528
Egil Hansen
@egilhansen:matrix.org
[m]
So if you take the approach i suggested and just invoke the ValueChanged event callback. Then you don't tie your tests to MudBlazors internals, and don't test their components, which you don't want to do.
Purendra-naik-ascendlearning-com
@Purendra-naik-ascendlearning-com
@egilhansen:matrix.org @ankit20071991_twitter how to mock members of base component like for example public sealed partial class TestDerivedComponent : BaseTestComponent. Im testing TestDerivedComponent which has in turn calls BaseTestComponent members
2 replies
Egil Hansen
@egilhansen:matrix.org
[m]
Correct, TryAdd returns a bool indicating if adding succeeded, so it cannot be chained. Why are you using TryAdd and not Add?
If you really need TryAdd, the do this:
var component = ctx.RenderComponent<MyComponent>(parameters => 
{
  parameters.TryAdd("param1", "value2");
  parameters.TryAdd("param2", "value2");
});
Ankit Garg
@ankit20071991_twitter
anyone who can help with MudBlazor?
Purendra-naik-ascendlearning-com
@Purendra-naik-ascendlearning-com
image.png
@egilhansen:matrix.org I see cascading param(State) value always null where as parameter Container is having value in below expression to rendercomponent var component = ctx.RenderComponent<MyComponent>(
ComponentParameterFactory.CascadingValue(nameof(MyComponent.State), valueState),
ComponentParameterFactory.Parameter(nameof(MyComponent.Container), valueContainer)
);
1 reply
Ankit Garg
@ankit20071991_twitter
@egilhansen:matrix.org Any idea if we can reset table state of mudtable. When I click on search I want to reset the current page.
3 replies
gismofx
@gismofx
Wondering if this is by design, but using RenderComponent and CSS Isolation is not coming through
4 replies
Egil Hansen
@egilhansen:matrix.org
[m]
So I'm trying to understand the test you want to write @gismofx. Can you explain?
Ankit Garg
@ankit20071991_twitter
Is there any way to test mud overlay
Christian Oleson
@Christian-Oleson
Anybody testing a file upload in bUnit? I'm a bit stuck on getting past that. I've got a component, which is a file upload, and no matter what I do I'm not quite getting the uploader right. The component is IMatFileUpload
I've tried something like this:
var fileUploader = cut.FindComponent<MatFileUpload>(); cut.InvokeAsync(() => { fileUploader.Instance.NotifyChange(new[] { fakeFileUpload }); }); cut.Render();
but it still appears as if the file is never uploaded.
Christian Oleson
@Christian-Oleson
NVM, I was looking at this for a colleague and didn't check the mock. It was the wrong type.
1 reply
Felipe Costa Gualberto
@FelipeCostaGualberto

Hello, frieds, how are you?
I have a Console application and and trying to execute:

var cut = context.RenderComponent<IndexPage>();

My component has the code:

var result = await _http.GetFromJsonAsync<ClientSchema>("api/application/GetClientSchema/1");

When this statement executed, I don't get an error, but the program execution abruptly ends, like when you press Ctrl+Break.
Do you know how can I make this statement work inside my component? Thanks!

5 replies
Egil Hansen
@egilhansen:matrix.org
[m]
I'm always so curious when I see "Message deleted" :)
Chris Sainty
@chrissainty
lol, that was a little message from my 11 month year old who was playing with my phone! I'm not sure it would have added much value 😂
4 replies
Gary Chan
@c0g1t8
@chrissainty thanks for keeping things real 😆
2 replies
Purendra-naik-ascendlearning-com
@Purendra-naik-ascendlearning-com
@egilhansen:matrix.org Need your help on Unit testing MudBlazor IDialogService as Dialog injected in component and Dialog.Show<ModalDialog>("", parameters) does not actually render ModalDialog. I'm adding this line in Test constructor ctx.Services.AddSingleton<IDialogService>(new DialogService()). Any idea how to fix this?
Egil Hansen
@egilhansen:matrix.org
[m]
@Purendra-naik-ascendlearning-com normally when you have something like a external 3rd party service like IDialogService you register a mock or fake of that instead of the real thing, and just verify with the mock that the expected method on the service was called. That way you don't end up testing 3rd party code.
Look at NSubstitute, JustMock or Moq for a mock library.
Then you can do ctx.Services.AddSingleton<IDialogService>(mockObject)
Ivan Josipovic
@IvanJosipovic
@Purendra-naik-ascendlearning-com, MudBlazor has pretty comprehensive Tests, have a look how they teste the IDialogService here, https://github.com/Garderoben/MudBlazor/blob/0696c060fd3b952eb96b81b97ac7e8ea922ac5c8/src/MudBlazor.UnitTests/Components/DialogTests.cs
1 reply
Kevin Ciliento
@Keviento

Hi ! My team and I are pretty new with Bunit and Blazor and we were wondering if there is a clean way to assert that a component has not been rendered in an Integration test context where the component under test is always the Index component and all services are injected with their real implementation excepting the HttpClient that is mocked with the suggested NuGet.

Currently, we are relying on time to assert that its has not been rendered like the following :

Action getComponentX = () => cut.FindComponent<X>;
cut.WaitForAssertion(() =>getComponentX.Should().Throw<WaitForFailedException>(), TimeSpan.FromSeconds(3));

A concrete exemple of the production use case would be when there is an @if statement.
Also, is there any hook letting us know when the Index and all its child component has finished rendering and all the async initialization have been completed ?
Thanks !

Egil Hansen
@egilhansen:matrix.org
[m]

hi @Keviento

in general, after a call to RenderComponent (or Render), the full render tree has been created. Then you can use cut.WaitForState. Its predicate will be called after each render, so if you have one or more async renders happening after the initial render, that predicate will be called after each.

To find out if a component exists in the render tree or not (e.g. if it has been rendered), I would probably use cut.HasComponent<T>(). It returns false if there is no child component in the render tree of that type.
Alternative is cut.FindComponents<T>().Count == 0
jhcorey
@jhcorey
Hello, I'm having a difficult time tracking down an example for mouse events. Specifically we're doing a mouse over to bring up a tool tip. The document page has a list... The built-in dispatch event helpers are: ...which includes Mouse Events, but what appears to be a link does nothing. Are there examples anywhere? Thanks!
1 reply
Brett McDonald
@bfmsoft
var cut = ctx.RenderComponent<BfmEnumInputSelect>(); I am getting that that is a namespace. My project is called BfmEnumInputSelect and component called BfmEnumInputSelect. Hw do I specify the component name? Or how do I find the name of the component? Been working on other stuff for a few months and converting to new version of BUnit, BTW love it.
11 replies
Egil Hansen
@egilhansen:matrix.org
[m]
You'll probably want to look at the new way of writing tests in razor files: https://bunit.dev/docs/getting-started/writing-tests.html#write-tests-in-cs-or-razor-files
Brett McDonald
@bfmsoft
image.png
I was just typing and ran a test and then it matched but, I am puzzled. It shouldn't match? Am I missing something?
This is .Net 6.0 and bUnit 1.2.49
SQL-MisterMagoo
@SQL-MisterMagoo
@bfmsoft I'm no bUnit expert, but it looks right - as you passed a RenderFragment into MarkupMatches - which will need to be rendered, which means the rendered markup to match is the <form> and matches the cut markup which is also a <form> ? As I say, I could be wrong.
Brett McDonald
@bfmsoft
The typo was that I passed the same markup twice. It shouldn't match.
I think I stand corrected, I must render the second batch and then check it. So it does match. My mistake
Egil Hansen
@egilhansen:matrix.org
[m]
Great, sounds right :)
gismofx
@gismofx
Hey everyone. Is there an example somewhere for perform a two-way binding parameter on a component? I.e. simulate changing the value via UI and then changing via code?
Egil Hansen
@egilhansen:matrix.org
[m]
@gismofx are you writing tests in razor or cs files?
Egil Hansen
@egilhansen:matrix.org
[m]
In razor files its super easy. Just define a local variable in your test, and bind it to the parameter like normal, e.g. Render(@<MyComp @bind-Value="variable" />)
Then you trigger whatever you need in the component to make it update the value, e.g. a click handler, and then you can assert against the local variable.
With .cs based tests, you just need to both pass in the original variable to the "Value" parameter, and a func that should be invoked when the value changes to the "ValueChanged" parameter.
I'm on my phone now, so hard to show more code, but do let me know if it answers it for you.
gismofx
@gismofx
@egilhansen:matrix.org I'm doing tests in .cs. Ill take a crack at it and come back if any questions. Thanks!
Egil Hansen
@egilhansen:matrix.org
[m]
@gismofx: if you have a component MyComp with an input field that is linked/bound to a Value parameter, and when it is changed, the ValueChanged EventCallback is triggered, then the following should work:
var value = "initial";
var cut = RenderComponent<MyComp>(ps => ps.Add(p => p.Value, value).Add(p => p.ValueChanged, x => value = x)));

cut.Find("input").Change("new value");

Assert.Equal("new value", value);
Here we are passing in the initial value (optional), and then we're passing in a lambda that to the ValueChanged parameter. In the lambda we simply update the value field in the test, so we know that it was triggered.
Egil Hansen
@egilhansen:matrix.org
[m]
Now, in a razor based test, the code is a little more simple:
var value = "initial"
var cut = Render(@<MyComp @bind-Value="value" />);

cut.Find("input").Change("new value");

Assert.Equal("new value", value);
These two tests does the same.