Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • May 08 17:08
    egil synchronize #391
  • May 08 17:08
    egil edited #391
  • May 08 17:08
    egil edited #391
  • May 08 17:08
    egil edited #391
  • May 08 17:08
    egil edited #391
  • May 08 17:08
    egil edited #391
  • May 08 17:08
    egil edited #391
  • May 08 17:07
    egil edited #391
  • May 08 17:07
    egil edited #391
  • May 08 17:07
    egil edited #391
  • May 08 17:07
    egil opened #391
  • May 08 17:02
    egil edited #388
  • May 08 17:01
    egil edited #388
  • May 07 11:33
    egil commented #388
  • May 07 08:29
    mrpmorris commented #388
  • May 06 19:34
    egil commented #388
  • May 06 18:48
    mrpmorris commented #388
  • May 06 12:19
    egil edited #388
  • May 05 20:15
    KristofferStrube commented #388
  • May 05 20:07
    egil commented #388
Egil Hansen
@egil
hang on, let me dig up an example
Then you just need to register it with the TestSontext's services collection, e.g.: ctx.Services.AddSingleton<NavigationManager, FakeNavigationManager>()
Jakob Reesalu
@jensengbg-jakob-reesalu
@egil Thanks for your reply! Ya, I already implemented something like this, I found an old thread where you discussed this with someone and they provided their fake navigator there. Sorry, I should've said this so you wouldn't spend time on that! But ok, then I know the scope of this kind of test :)
Still nice to see that page with all those tests, I might use it to find other answers later on ^^
Jakob Reesalu
@jensengbg-jakob-reesalu
Actually, your fakemanager was a little cleaner so I'll shamelessly steal it xP
Egil Hansen
@egil
haha there is no shame in that, its there for the taking.
there is a whole series of videos of me building all the tests you see in that blazor-workshop repo: https://www.youtube.com/channel/UCcHRuajIkdHagmpdkE01YPg
if you want to learn more.
Felipe Costa Gualberto
@FelipeCostaGualberto
Hello! How can I test a component in a specific route?
Felipe Costa Gualberto
@FelipeCostaGualberto
I figured out. Just pass the route's arguments as parameters.
Egil Hansen
@egil
great, glad you sorted it out.
Egil Hansen
@egilhansen:matrix.org
[m]
Test from Elements client
Thomas Castiglione
@gulbanana
just dropping in to say that bUnit continues to work very well. thanks egil and everyone who's contributed - this tool really helps my projects out
Egil Hansen
@egilhansen:matrix.org
[m]
Awesome @gulbanana
George Fabish
@thepigeonfighter
I've heard a lot about this project and am excited to get to use it today. So far its working fantastic. Great job! I see in the docs how to fake authorization in unit tests in C# but is there a way to do that as simply in Razor?
George Fabish
@thepigeonfighter
I think i may have got it to work by just copying this code and reapplying it for the Fixture type. Not sure if that is the cleanest solution though.
https://github.com/egil/bUnit/blob/74fd44bf548417bfb75971d498a996816387904f/src/bunit.web/TestDoubles/Authorization/FakeAuthorizationExtensions.cs#L16
Egil Hansen
@egil
@thepigeonfighter you should be able to do it with <Fixture> style tests as well. Just call fixture.AddTestAuthorization()before calling fixture.GetComponentUnderTest()
A Fixture is a TestContextBase.
George Fabish
@thepigeonfighter
If it was a snake it would have bit me, can't believe I missed that. Thanks.
Egil Hansen
@egil
@thepigeonfighter yeah, its not super obvious nor well documented, so I think you are excused. Another feature I need to document is an new approach to writing tests in razor components. You can see examples of this in this sample's tests project: https://github.com/egil/blazor-workshop.
George Fabish
@thepigeonfighter
Great! I'll check that out thanks.
George Fabish
@thepigeonfighter
One more issue I just ran into is when using an EditForm component with a button as a child element the EditForm get triggered by clicking on that button. But if I try to do a "Click" via bUnit it says there is no click handler registered, which makes sense. But not sure how to submit the form via bUnit's api?
George Fabish
@thepigeonfighter
Sorry my fault I just saw an example of this is the workshop link you shared. Thanks.
Egil Hansen
@egil
No need to be sorry. It can be hard to discover things like this.
Glad you figured it out.
Brett McDonald
@bfmsoft
I am developing an Blazor HTML5 canvas application. I am getting a lot working so that isn't the issue. What I am trying to figure out is how to test the Canvas code. I was thinking to capture a bitmap then test comparing the output of the canvas to check for regression. Using like Selenium in xUnit or bUnit? I am looking for ideas...
Egil Hansen
@egilhansen:matrix.org
[m]
@bfmsoft isn't the problem that bUnit doesn't run JavaScript, and canvas is entirely driven by JavaScript?
With bUnit, the only thing you can do is have it record the JavaScript invocations and assert against those. Not sure the value of that kinda test though.
George Fabish
@thepigeonfighter
So I've ran into an issue trying to follow the new razor testing patterns put forth in https://github.com/egil/blazor-workshop. the following code results in some unexpected results. When I inspect the values after these "change" calls the first "change" call appears to not be setting the value in the component's markup. I suspect it has something to do with the component not being completely rendered?
 var cut = Render(@<ManageUser ConfirmPasswordChange="DummyActions.AlwaysTrueFunc"
                                      OnPasswordUpdate="DummyActions.OnEvent"></ManageUser>);


        cut.Find("#new-password").Change("Test123!");
        cut.Find("#new-password-confirm").Change("Test123!");
        cut.Find("#old-password").Change("Admin123!");
For context the ManageUser component uses OnInitializeAsync. I have switched the order of these find statements and whatever the order the first of the three calls is null in the rendered markup while the other have expected values.
Egil Hansen
@egil
hi @thepigeonfighter, that has nothing todo with the new razor testing pattern. If you have some async code in a component life cycle method, is is like, as you say, that it is because the component has not finished rendering when you start issuing your Find and Change calls. You likely need https://bunit.egilhansen.com/docs/interaction/awaiting-async-state.html or https://bunit.egilhansen.com/docs/verification/async-assertion.html to help you.
George Fabish
@thepigeonfighter
Ok interesting, is there any other way to figure out when a component has finished rendering other than checking for markup existing?
Egil Hansen
@egil
@thepigeonfighter hmm, no that is really the thing you are looking, the output from the component. however, if your component has a property that is set when it is done rendering, e.g. MyCompoent.ImDoneNow, then you can also inspect that. E.g. cut.WaitForState(() => cut.Instance.ImDoneNow);
George Fabish
@thepigeonfighter
Ok I was wondering about that. It's a shame Blazor doesn't offer something like that by default on components. An IsInitialized boolean would be perfect.
Egil Hansen
@egil
well, in Blazor, we never watch the components from the outside, so it being initialized is implicit in that its life cycle methods has been called.
I would also recommend that you assert on expected output, since that will make your tests more stable. I am planning to add a WaitForElement/WaitForElements that will make it a little less verbose.
For now, I would do cut.WaitForState(() => cut.FindAll("elementSelector").Count == 1)
George Fabish
@thepigeonfighter
Ok good to know, thanks! It working now.
Egil Hansen
@egil
When WaitForElement is there, then you can do a var elm = cut.WaitForElement(cssSelector). So it works like Find, just that it waits.
George Fabish
@thepigeonfighter
Actually in my use case it was finding the input element. It just wasn't setting the value of the input. If that makes sense. Looking at how the page loads naively I'd guess that the input tag gets rendered and then the value set by blazor's javascript? Not sure how long the delay between those two events are. So in my particular case I'm not sure waiting until i could find the element would do the trick?
Egil Hansen
@egil
Ahh, yeah, that might be it.
I have one "bug" that might be related to what you are seeing: egil/bUnit#46
Egil Hansen
@egilhansen:matrix.org
[m]
Hey folks, it's here. V1. Release notes here: https://github.com/egil/bUnit/releases/tag/v1.0.16
Christian Oleson
@Christian-Oleson
Awesome, thanks for all the hard work!
Gary Chan
@c0g1t8
🙏🙏🙏🎉🎉🎉
Peter Morris
@mrpmorris
Congratulations!!
Egil Hansen
@egil
Thanks folks, and for all the help getting here.
Martin Muller
@mmuller88
Thank you :)