-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing components that use Telerik components #141
Comments
Thanks for a well described question. Makes it much easier to provide help. I do not know how the click bindings are done in Teleriks components, but It could be that his is related to issue #119, i.e. that Telerik binds click handlers to elements higher up the DOM tree, and not on the individual elements. To verify this, inspect If the dropdown you are trying to change is a select or input element, you might need to use |
Thank you for the quick reply! I inspected the markup and didn't find any attributes with
Tryng to change the dropdown value using |
OK. The Just for comparison, can you copy the same markup from the browser when rendering the component there? |
I removed some unimportant things like navbar,
|
Interesting. Do you see items in the dropdown in the browser? In that case, it looks as if it created using JavaScript. |
Ok. I thought Telerik was not depending on JavaScript in their components in this way. That will make it hard to test with bUnit then. But you would also be dedicating a test to testing at least some parts or Teleriks components, which is probably a waste of time. The alternative is to make your I am also thinking about shallow render/mocking components, and that would certainly solve this issue as well, but alas, that is not support currently. |
The TelerikDropDown uses an animation container to create a drop-down effect. We use this because the default HTML drop down doesn't allow for us to have templates and other enhancements we add. Animations require JS to work properly, Blazor doesn't support them at the framework level. I don't believe we're doing what is classically referred to as DOM manipulation here. Instead it's a JavaScript interop that enables us to identify when the animation starts and stops. |
Hello @EdCharbeneau and thank you for the answer. |
@EdCharbeneau, I imagine there is a have a good reason for Teleriks approach. My general impression is that the Telerik components are generally following Blazor best practices. That said, from what @joonastamm has shown here, it does look like JavaScript is used to both generate the items in the drop down and listen to click events on them and the drop down, which means that bUnit have nothing to trigger. @joonastamm if the above is true, then your best bet is to make your |
No worries, I'll check with engineering to see what the lifecycle is like for this one. Something may have changed since I looked at the source last. ... Just looked myself. We don't render any HTML that I can see. However, animate, change some classes, and data attributes at runtime. Also, there are quite a bit of events added. This is likely the problem. The component and each drop-down item receive event handlers for accessibility, ex: keyboard navigation. There are also handlers for multi-select. Which is likely to cause trouble with testing since JS isn't running and adding the handlers. muli-select requires us to check for keys and may override the single select handler. Unfortunately Blazor doesn't support all of the events we need. |
@joonastamm This is typical with components that require animation. Like Drawer, Menu, and Grid filter menus. Sorry it's making testing difficult. |
@EdCharbeneau thanks for checking up on this. I am looking into making scenarios like these easier by finding a way to enable shallow rendering (#17) or mocking/faking certain components (#53). Until then, bUnit is certainly meeting its limits in scenarios like this. Ill close this issue as it seems there is no easy way to hook into this directly for now. |
I have a Blazor component (page) that uses Telerik components which I wish to test but find that the Telerik handles clicks etc differently from regular Blazor components. Let's say we have a component
<SomeComponent>
:And I wish to test that when "Option2" is selected then
SomeService.SomeMethod
is called with the chosen value. I have set up a test:SomeComponentTests.razor:
and SomeComponentTests.razor.cs:
but always get the same exception on Click() method call. The css selectors seem to be correct as when running the application and calling these methods via console using jQuery (e.g.
$('#value-picker').click()
) everything works as expected (opens the dropdown).How would it be possible to achieve the desired result (get the test to work)?
@mihail-vladov @EdCharbeneau
The text was updated successfully, but these errors were encountered: