Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Mar 06 18:34
    egil commented #330
  • Mar 06 18:27
    mikes-gh commented #330
  • Mar 06 07:36
    egil commented #330
  • Mar 05 21:14
    mikes-gh commented #330
  • Mar 05 21:13
    mikes-gh commented #330
  • Feb 28 14:49
    egil opened #336
  • Feb 24 20:41
    egil opened #333
  • Feb 23 09:31
    egil closed #303
  • Feb 22 10:11
    egil edited #329
  • Feb 22 10:07
    egil edited #329
  • Feb 22 09:34
    codecov[bot] commented #328
  • Feb 22 09:34
    codecov[bot] commented #328
  • Feb 22 08:51
    codecov[bot] commented #328
  • Feb 22 08:21
    codecov[bot] commented #328
  • Feb 21 14:00
    codecov[bot] commented #328
  • Feb 21 14:00
    egil synchronize #328
  • Feb 21 13:58
    codecov[bot] commented #328
  • Feb 21 13:56
    codecov[bot] commented #328
  • Feb 21 13:56
    egil synchronize #328
  • Feb 21 11:23
    codecov[bot] commented #328
In that case, I think the easiest approach is to use razor based testing (if you are using xUnit) ... https://bunit.egilhansen.com/docs/getting-started/writing-razor-tests.html
Egil Hansen
@egil
@therubble_twitter Otherwise, this might work, although we are getting to the limit of what the c# only builder syntax can do:
            var cut = RenderComponent<EditForm>(ps => ps
                .Add<MyForm, EditContext>(p => p.ChildContent, ctx => myformParams => myformParams.Add(x => x.Model, ctx.Model))
            );
Havent testet, but it should work.
Patrick Swayc
@therubble_twitter
I'll give it a whirl
You happy for me to update the bunit docs with this info if it works?
I want to build up a set of how-to guides at some point in the docs, but for now it would be awesome if you could add your example to https://github.com/egil/bUnit/discussions?discussions_q=category%3A%22Show+and+tell%22
E.g. with a title such as "How to render component inside an EditForm".
Egil Hansen
@egil
Or whatever you thing :)
Patrick Swayc
@therubble_twitter
Will do, let me get this up and running first
Egil Hansen
@egil
Forgot to add that you also have to pass a model to the EditForm's parameters, e.g.:
var cut = RenderComponent<EditForm>(ps => ps
    .Add(p => p.Model, myModelInstance)
    .Add<MyForm, EditContext>(p => p.ChildContent, ctx => myformParams => myformParams.Add(x => x.Model, ctx.Model))
);
Jochem de Kruijf
@jochem4207
Hi all, hows it going :)?
Egil Hansen
@egil
busy busy, how are you?
Jochem de Kruijf
@jochem4207
Lost my touch and energy for a few days but picking up soon! Energy is back. Busy as always with work. Just started reading trailblazer (book from the Salesforce CEO)
Egil Hansen
@egil
Good, my energi level is more or less controlled by how my kids sleep these days :)
Jochem de Kruijf
@jochem4207
Haha i see, ive many fathers as coworkers. You know a little bit of alcohol or sleep medicine hahah #shitty tips
Egil Hansen
@egil
for the kids or the parents?
What I've learned is the small kids dont care about your hangovers, they wake up at 6am anyway, so I prefer not to have them any more :)
Jochem de Kruijf
@jochem4207
Hahah for the kids
Oof. 6 am on a hangover. Idk if the hangover already started by then or its still the drunk phase
Egil Hansen
@egil
:)
paevans87
@paevans87

Hey all - hoping someone is able to help out with an issue I'm having writing some tests. I have a cascading parameter that takes some services from DI. I'm trying to create tests for my child component and pass in the CascadingValue which from what I've read seems like it should be as simple as:

var cut = ctx.RenderComponent<Toast>(ComponentParameter.CreateCascadingValue("ParameterName", myValue)

In my situation here myValue is a `Mock<ParentComponent>' but whenever I debug the test the value is null so it's not picking it up

Egil Hansen
@egil
Hi @paevans87, is your cascading parameter named or unnamed?
The easiest, if you dont want to think about it, is to use the builder pattern to pass parameters, e.g.:
ctx.RenderComponent<Toast>(ps => ps.Add(p => p.ParameterName, myValue));
paevans87
@paevans87

Hi @paevans87, is your cascading parameter named or unnamed?

I haven't come across this post! I suspect that'll have all the info to get me up & running, thanks!

Egil Hansen
@egil
Hopefully, there is lots of documentation on that site :)
Forex Ray
@forex.ray.v1_gitlab
hello everyone, I'm new here... Let me start by saying Hello from England :)
is there a good working example of bUnit using Async web pages? I have a simple project which loads data base from database. when i test it with bUnit all is see is "loading"... and it is completing testing before data is loaded. so its a sync call. how can i make it async call... so bUnit waits for the page to completely load the data and then triggers test?
or a link to youtube video demoing the async funtionality for bUnit?
would like a working example and i will be able to figure it out from there
any such link available?
Egil Hansen
@egil
Welcome @forex.ray.v1_gitlab to the community
Its a common scenario. You can look at https://bunit.egilhansen.com/docs/interaction/awaiting-async-state.html and https://bunit.egilhansen.com/docs/verification/async-assertion.html for general input on handling async/delayed rendering of the component under test
Are you loading data from a real data source in your tests, or are you mocking your data source?
Forex Ray
@forex.ray.v1_gitlab
hello @egil , we are loading the real data from the APIs and it's not a mock. That's why there is time delay in the data load.
Egil Hansen
@egil
Then you can use WaitForState(() => cut.FindAll("css selector for element that should show up").Count > 1)
Forex Ray
@forex.ray.v1_gitlab
ah ok. let me try that. Thanks @egil
Egil Hansen
@egil
Ohh forgot to mention, if you need more than 1 second of wait time, you can change that by passing a second parameter to WaitForState, e.g. WaitForState(() => ...., TimeSpan.FromSeconds(xx))
camelCaseSharp
@camelCaseSharp
I am thinking about using bunit to write BDD style tests, these typically involve writing longer UI scenarios than a TDD style unit test. Is is possible for a single bunit cut to navigate between two routable Blazor components (also known as pages)?
Egil Hansen
@egil
Hi @camelCaseSharp
I think so, but I am not sure I exactly understand what you are trying to do.
bUnit doesnt look at the @page directive in components though, so the navigation step will have to be manual.
That said, there is nothing preventing you from calling var page1 = RenderCompoent<Page1>() and var page2 = RenderComponent<Page2>() in the same test class.
And you can pass in the same state to both components. You can even pre-register a cascading value that both should receive through the TestContext.RenderTree, if that is how you share state.
Egil Hansen
@egil

That said, there is nothing preventing you from calling var page1 = RenderCompoent<Page1>() and var page2 = RenderComponent<Page2>() in the same test class.

Correction, IN THE SAME TEST METHOD. You can call RenderComponent as many times as you want within the same test.

camelCaseSharp
@camelCaseSharp
Thanks for the feedback Egil. I was thinking about creating some BDD business test scenarios such as "When I want to pay out approved insurance claims, I first click on 'Pending Claims' in the application dashboard, then select the first approved claim listed then on the summary claim screen click the 'Issue Payment' button.". In a typical LOB Blazor app that scenario might traverse across 3 top level routable components. I gather from your first response that the Blazor navigation manager and location changed events are not hooked into the scope of a CUT?
Egil Hansen
@egil
not by default
But if you want to use navigation manager, you simply register one through the Services collection