Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • May 17 23:12
    egil synchronize #397
  • May 17 22:32
    egil edited #396
  • May 17 21:36
    egil edited #396
  • May 17 17:42
    egil commented #396
  • May 17 17:42
    egil edited #397
  • May 17 17:42
    egil edited #397
  • May 17 17:41
    egil edited #397
  • May 17 17:41
    egil edited #397
  • May 17 17:41
    egil edited #397
  • May 17 17:41
    egil opened #397
  • May 17 16:17
    FlorianRappl commented #396
  • May 17 16:17
    FlorianRappl commented #396
  • May 17 15:46
    egil commented #396
  • May 17 15:41
    egil edited #396
  • May 17 15:41
    egil edited #396
  • May 17 15:34
    egil edited #396
  • May 17 14:45
    egil edited #396
  • May 17 14:16
    egil edited #396
  • May 17 13:42
    egil edited #396
  • May 17 13:37
    egil edited #396
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 :)
Diako
@dkezri
Hi! is there a way to test input (type file) events like change() or input() events ?
Egil Hansen
@egilhansen:matrix.org
[m]
hi @dkezri
I have actually not tried that myself. Can you provide a minimal example of the component you want to test, and what you want to test?
Egil Hansen
@egilhansen:matrix.org
[m]
hey folks, im live on https://www.twitch.tv/egilhansen. ill be talking about github workflows, strong name signing of bUnit, and any questions you might have.
Egil Hansen
@egilhansen:matrix.org
[m]
Hey folks, wanna help me design the API for mocking of components in bUnit tests? Im going live now on twitch.tv/egilhansen to work on just that.
Brett McDonald
@bfmsoft
I am converting to the new version (BTW great job). I used a Setup method that was called from the Fixture component? Do you just inline that code in the Fact test?
Egil Hansen
@egilhansen:matrix.org
[m]
Uhm no, there are no changes to the fixture and SnapshotTest test component's.
Have you added the bunit.web.testcomponents package and removed the bunit.xunit package?
Ohh and thanks btw. @bfmsoft
Egil Hansen
@egilhansen:matrix.org
[m]
Hey folks I'm live on Twitch with more design/implementation work on the component double feature in #bUnit. Learn more about this here bUnit-dev/bUnit#388 and join the discussion live at https://www.twitch.tv/egilhansen
Egil Hansen
@egilhansen:matrix.org
[m]
Hey all, would love some feedback on the design of the component double/replacement feature in working on in bUnit: bUnit-dev/bUnit#388
Brandon James
@brandon-james105
Hi. I am having an issue with bUnit and a component using the Authorize attribute in regards to user roles. The component should not be rendered for a user without a role. I am using Telerik controls. Is there anything else I should be doing for the component to behave properly? My guess is perhaps I should wrap the component with another one but I'm not sure exactly which. I have already done test setup and applied the TestAuthorization for the user I am checking.
Egil Hansen
@egilhansen:matrix.org
[m]
Hi @brandon-james105