Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Apr 28 13:50
    linkdotnet commented #694
  • Apr 28 13:48
    linkdotnet commented #694
  • Apr 28 13:41
    linkdotnet commented #694
  • Apr 28 13:40
    linkdotnet commented #694
  • Apr 28 13:32
    linkdotnet edited #695
  • Apr 28 13:31
    linkdotnet edited #695
  • Apr 28 13:28
    linkdotnet opened #695
  • Apr 28 12:59
    linkdotnet commented #694
  • Apr 28 11:37
    linkdotnet assigned #694
  • Apr 28 10:56
    dnfadmin commented #559
  • Apr 28 10:11
    linkdotnet commented #694
  • Apr 28 10:04
    egil commented #694
  • Apr 28 09:49
    linkdotnet commented #694
  • Apr 28 09:20
    egil commented #577
  • Apr 28 09:12
    egil labeled #694
  • Apr 28 09:12
    egil opened #694
  • Apr 28 09:07
    egil closed #691
  • Apr 28 09:06
    egil closed #693
  • Apr 28 09:06
    egil commented #693
  • Apr 28 06:52
    dnfadmin commented #561
Jack Smith
@QuantumFox12_gitlab
alright thx for your help anyway have a nice day :)
NikolayRenziglov
@NikolayRenziglov
Hi there. Can anybody makes clear on how to test the Component which makes a WebAPI request during the test? It simply makes an async request like "await httpClient.PutAsync(uri, new FormUrlEncodedContent(data));" For me it just immediately returns to the test code with waiting for result. What technique can be used here? Thanks
2 replies
Egil Hansen
@egilhansen:matrix.org
[m]
But also, refactor your code such that it doesn't use HttpClient directly but an interface/service instead that wraps HttpClient. It's much easier to mock and control it's return value (e.g. a completed task) such that you do not need to deal with asyncness in your test.
Necrowizard
@Necrowizard_twitter

Hey, question, I'm trying to use bUnit from source, and also trying to use Microsoft.AspNetCore.Components / Microsoft.AspNetCore.Components.Web from source, (because I'm debugging something)
However, when I point bUnit to the sources instead of the nuget, I'm getting loads of errors about missing namespaces from System.ComponentModel : https://i.imgur.com/tDP8ld8.png

Anyone have an idea how to solve this? It kinda seems like I'm missing some implicit usings, because the namespaces aren't in the files either

3 replies
Necrowizard
@Necrowizard_twitter
Specifically what I'm trying to debug is: when I'm calling context.RenderComponent<>(); with my component, it just throws a null reference exception without telling me anything useful. Something in my component is null. I was trying to see if I can add a fix somewhere to tell me exactly what is null, if that's possible. The exception is being thrown from somewhere inside base.ProcessPendingRender();
Egil Hansen
@egilhansen:matrix.org
[m]
Are you using component factories?
Does your component work if you use it in a blazor app?
Necrowizard
@Necrowizard_twitter
eehhm, I don't know if I'm using component factories, not sure what they are, so guess not
the component does work when running it, yea. Though the goal wasn't really to solve the issue specifically for my component, but to patch it for everyone. So instead of it just throwing a null exception, telling me exactly which property is null
I have this test, "TestEveryComponentShouldRender" - that just finds everything that's an IComponent in my solution and tries to render it with bunit to make sure nothing crashes... and sometimes some things to crash with random exceptions that are difficult to fix
Egil Hansen
@egilhansen:matrix.org
[m]
Ok, if you can narrow down the issue, post the component and test to the discussion forums on GitHub and we'll better be able to help you.
It's not a known problem.
Necrowizard
@Necrowizard_twitter
no? it's not a common thing? oh, it's an issue that's been happening to me lots of times. But I'm constantly running tests with randomized parameters on a couple 1000 components... I can probably make something reproducible
3 replies
Egil Hansen
@egilhansen:matrix.org
[m]
Hmm boarding a plane, but would love to take a look at the code in the coming days, if you can share it. A runnable project is preferable.
If you post something on the discussion forum I or somebody else might be able to help you out.
Necrowizard
@Necrowizard_twitter

alright sure. I think it's pretty easy to reproduce. You kinda just have to make a .razor file throw a null reference exception. Maybe you have bind null to something that's not expecting it, but that's it.

in my project I made a null check helper extension which is like this public static bool IsNull(this object input, [CallerArgumentExpression("input")] string message = null, [CallerMemberName] string caller = "")
and actually tells you which expression threw the null exception. Was hoping I could add something similar in whatever is throwing that null exception during rendering

Chris Martin
@gt5193
When mocking a child component, I shouldn't need to worry about the child components dependencies correct? I know there's not a whole lot of context to that question but figured it would start a conversation at least :)
3 replies
Egil Hansen
@egilhansen:matrix.org
[m]
How do you mock it?
If you are using Stubs from bUnit, you are completely replacing the component with a new type. However, if you are mocking it using Moq or similar, then your mock will have the same dependencies.
You can get away with using Stubs if you do not reference Bar in your Foo component using @ref.
olemalik
@olemalik
Hi! How I check read only , I tried this way cut.WaitForAssertion(() => input.HasAttribute("readonly").Should().BeFalse() , but it is returning true. This is my out put markup : <input class="mud-input-slot mud-input-root mud-input-root-text mud-input-root-adorned-end mud-input-root-margin-dense mud-select-input" type="text" value="ABC" blazor:oninput="2" blazor:onchange="3" readonly="" blazor:onblur="4" inputmode="text" blazor:onkeydown="5" blazor:onkeypress="6" blazor:onkeyup="7" maxlength="524288" blazor:elementreference="">
Egil Hansen
@egilhansen:matrix.org
[m]
I see a readonly attribute in your markup, so seems like things are as expected
olemalik
@olemalik
Hi! @egilhansen:matrix.org , Yes your right but value is always empty, only for the MudSelect I am having this issue, other place it is working fine
Egil Hansen
@egilhansen:matrix.org
[m]
you are using HasAttribute. That just checks if there is an attribute, not what its value is
olemalik
@olemalik
image.png
olemalik
@olemalik
var hasReadOnlyAttribute = input.GetAttribute("readonly"); hasReadOnlyAttribute.Should().Be("true"); but when i use this way also the value is empty
Egil Hansen
@egilhansen:matrix.org
[m]
thats because they are the same. readonly="" and readonly="true" means the same in HTML5. So its completely legal what MudBlazor is doing.
olemalik
@olemalik
@egilhansen:matrix.org <input class="mud-input-slot mud-input-root mud-input-root-text mud-input-root-adorned-end mud-input-root-margin-dense mud-select-input" type="text" value="Yes" blazor:oninput="2" blazor:onchange="3" readonly="" blazor:onblur="4" inputmode="text" blazor:onkeydown="5" blazor:onkeypress="6" blazor:onkeyup="7" maxlength="524288" blazor:elementreference=""> regardless of true or false it is showing readonly=""
1 reply
Egil Hansen
@egilhansen:matrix.org
[m]
Ok.
Koen Koninckx
@koninko
Hi, I was looking at this page, but it seems to be empty? https://bunit.dev/docs/test-doubles/mocking-localizer.html
Egil Hansen
@egilhansen:matrix.org
[m]
yeah, its yet to be written.
but I think you can find examples in the discussions forums on github
Koen Koninckx
@koninko
Hi thx for your fast reply, unfortunately the example is not using moq
Egil Hansen
@egilhansen:matrix.org
[m]
Ok, well how to mock an interface using Moq is probably something you can find docs on at their website.
When you have a mock of IStringLocalizer just register it to the services collection on bUnits TestContext.
Koen Koninckx
@koninko
Hi thx, yes I managed to get it work
Tim Almond
@timalmond

Hello. I thought I'd join the chat, as I'm using BUnit and really liking it. I have and I'm going to have questions/general thoughts. I should buy you a coffee, Egil, if it's not too expensive in Iceland!

One thing that I think would be useful and something that I am happy to contribute to is the documentation around how to use event handlers with some basic types and then how to check results. I found myself struggling with checking the state of the HTML after a change. I can use var cut = ctx.RenderComponent<HelloWorld>() and check cut.Markup but after an event click on a radio button, cut.Markup is still the same, and I'm not sure what is the best way to get the revised Markup (this may just be that I am missing something).

THop
@thopdev

Hi @egilhansen:matrix.org

We updated a MudBlazor but now i get errors in my bUnit test from Render Handle with the message: The render handle is not yet assigned.

Any clue how i could fix it?
Egil Hansen
@egilhansen:matrix.org
[m]
its most likely related to a component not being instantiated by the Blazor renderer but by you manually, and thus it does not have a render handler assigned.
Is there a service registration you need to add?
THop
@thopdev
Thanks for the reply
i have the services added in je di container
Egil Hansen
@egilhansen:matrix.org
[m]
ok, i know the people that build MudBlazor are using bUnit quite heavily to test it, so they might know what you are missing.
I unfortunately dont have any ideas, not been using MudBlazor myself.
THop
@thopdev
Oke Thanks for the time, i asked them but they had also no clue
ill check their tests and maybe find something
Peter Morris
@mrpmorris
Do any of you have "host your own auth" in your Blazor WASM apps?
Paul Trotter
@ptrotter1
Is there currently a way to get razor tests to show up in Rider's Unit Test explorer?
1 reply