feat: Add FindComponent on IElement (#153)#1738
Conversation
|
The name might be misleading as we have already |
|
So if |
|
Related; i have been thinking that WaitForElement and Find could just be one method, e.g. Makes test more resilient, e.g., if component introduces an async aspect, the test does not have to change. |
So something like this: Parent.razor <button>Btn</button>
<ChildComponent/>Test.cs var cut = Render<Parent>();
var btn = cut.Find("button");
var child = btn.FindComponent<ChildComponent>();The |
Basically that would only mean relabelling The same should be true for: |
4107571 to
75bd705
Compare
| /// <summary> | ||
| /// Retrieves the first component of type <typeparamref name="TComponent"/> that is rendered inside the specified <paramref name="element"/>. | ||
| /// </summary> | ||
| public static IRenderedComponent<TComponent> FindComponent<TComponent>(this IElement element) |
There was a problem hiding this comment.
If we are unsure, we can also add
[Experimental] Attribute on top
|
Why is it closed? Seems like pretty much useful |
|
The PR did not cover all the cases we want and we found it is not in a state where we want to release it - especially because there are edge cases where |
FindComponent<TComponent>This PR allows users to call
FindComponenton anIElement1. Fixes #153It should cover all the basic scenarios (see tests), even when using
ElementReferences(that should stay valid when usingFindComponent).The idea is that we can hook into the
CssSelectorElementFactory(or the any other factory that inherits from IElementWrapperFactory or better the newIComponentAccessor) to retrieve the elements rendered. If that way doesn't work, we use theBunitRendererand basically go through everything there (more expensive, but we could also solely rely on that).The last one happens if we have a
ParentComponentthat gets rendered, but we do acut.Find("...").FindComponent<ChildComponent>.Considerations
The API forces the user to specify the desired output component type:
FindComponent<TComponent>- we could also offer a version, where it "just" takes the direct parent component (as anIComponent).1 It does not work in
INode, so users can't use something like:cut.NodeList.First().FindComponent<TComponent>();because I have no idea on how to hook into that pipeline. Maybe we some factories of Anglesharp, but I am not too deep into that at the moment.