You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm implementing an integration test with bUnit on a Blazor wasm component who use TelerikTextBox component.
I need to set the TelerikTextBox value as it can be binded to the associated component property:
varcut=RenderComponent<MyComponent>();cut.Find("input").Change("test");// Change the value of the input fieldvaruserName=cut.Instance.UserName;// Will be "test"
As you can see we are leveraging the Change method. For your approach you could use something like that:
We need to trigger to Blazor Pipeline. In our case we do this with Change. Now we changed the textbox and therefore also the UserName property should be set.
Thanks @linkdotnet, using Change method it raise an exception, because the element does not have an onchange handler.
I solved using the Input method, and call the StateAsChanged method of the component (as StateHasChanged is a private method i used reflection to call it)
Hey @Gambero81
glad you could sort things out. Yes it could be that you need Input. It depends how TeletrikTextBox works.
I am not sure why you would need the StateHasChanged in this scenario. The Input() should invoke another render-cycle anyway. It does not work without the StateHasChanged?
If your issue is sorted, could you close it? Still we can discuss the StateHasChanged but I guess your original problems is resolved, or?
Activity
linkdotnet commentedon Feb 28, 2022
Hey @Gambero81.
I am not an expert with Teletrik but the general approach should be as following:
If you have a component like this:
With the following test:
As you can see we are leveraging the
Changemethod. For your approach you could use something like that:We need to trigger to Blazor Pipeline. In our case we do this with
Change. Now we changed the textbox and therefore also theUserNameproperty should be set.Gambero81 commentedon Feb 28, 2022
Thanks @linkdotnet, using
Changemethod it raise an exception, because the element does not have anonchangehandler.I solved using the
Inputmethod, and call theStateAsChangedmethod of the component (asStateHasChangedis a private method i used reflection to call it)linkdotnet commentedon Feb 28, 2022
Hey @Gambero81
glad you could sort things out. Yes it could be that you need
Input. It depends howTeletrikTextBoxworks.I am not sure why you would need the
StateHasChangedin this scenario. TheInput()should invoke another render-cycle anyway. It does not work without theStateHasChanged?If your issue is sorted, could you close it? Still we can discuss the
StateHasChangedbut I guess your original problems is resolved, or?EdCharbeneau commentedon Feb 28, 2022
@Gambero81 Have you added to the test:
These are required for all Telerik Components to work properly.
Here is a sample: https://github.com/telerik/blazor-ui/blob/master/testing/bUnit-justmock/Telerik.Blazor.BUnit.JustMock/DemoSample/ExampleModelTest.cs
Gambero81 commentedon Mar 1, 2022
@linkdotnet yes, using
Inputmethod and callingStateHasChangedthe problem is solved but i think it's not the standard way..@EdCharbeneau yes i added
Services.AddTelerikBlazorandTelerikRootComponent, this is not the problem, telerik components are recognized wellif i use
cut.FindComponents<TelerikTextBox>().FirstOrDefault(txt => txt.Instance.Id == "txtUserName")?.Instance;i get the
TelerikTextBox, but to set it's value the only way i found is:StateHasChangedto the component (this is the hack, because this method is protected)If i not call
StateHasChanged, the binding propertyUserNameof the controller is not updated.egil commentedon Mar 1, 2022
Hi all, I'm converting this to a QA discussion as it does not seem to be an issue with bUnit.