-
Notifications
You must be signed in to change notification settings - Fork 668
Find / FindRef: wrapper function to find element based on ref #67
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
Comments
I think this is a good idea, but I don't think we should add an extra method. We could extend find({
selector: 'refs',
value: 'value'
}) Then we could extend it to other selectors, like find({
selector: 'props',
value: 'value'
}) |
I wonder how many alternate use cases we would have for a selector other than CSS, component name, or $ref. I'm not sure if component with prop: |
But, if we do want to go with the selector/value find/findAll functions, I could start a PR. Initially it could look for $props / $refs. I guess the tough part would be matching |
I think we should just add support for refs at the moment ☺ |
@eddyerburgh To make it a little more concise, how do you feel about: find({ ref: 'myRefName' }) |
Yep that looks good 👍 |
Great, updating the PR to reflect this. Currently, the validation error messages for find/findAll display: If we're going to start with refs for now, we could use:
Or My only concern with the latter is that it may be too vague. |
Ah that's a good point. If we add this then we need to:
That's a fairly big change. Before we go further, I would like some input from others. Do we want to extend the selector to include { refs: 'refName' } |
So, one thing other thing to note: When selecting $refs, we rely on the $ref property to be available on the wrapper.vm, because we want to limit the results to this scope. This is one of the benefits of $refs. If we are using a wrapper on a non-Vue HTML Element, we should not allow selecting by $ref. |
Ok, we can add a validation error for that
…On 4 Oct 2017 14:56, "matt-oconnell" ***@***.***> wrote:
So, one thing other thing to note: When selecting $refs, we rely on the
$ref property to be available on the wrapper.vm, because we want to limit
the results to this scope. This is one of the benefits of $refs. If we are
using a wrapper on a non-Vue HTML Element, we should not allow selecting by
$ref.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMlbW5-IXCiceR2nBtZ9maQi39GG5R2oks5so457gaJpZM4Pq00C>
.
|
The PR for this change mentioned wanting some feedback from the community, so I thought I'd chime in. This would be great to have, I liked the initial suggestion of having |
Thanks for the feedback @skray. I'm happy for this work to continue. @matt-oconnell do you have any blockers? |
This is pretty much fully implemented in the corresponding PR. The blocker was that the Flow types were invalid (specifically |
I think we'll have to use any until proper flowtypes are exported from Vue — vuejs/vue#5027 |
This can be closed, released in |
Suggestion for additional functionality
Currently, there is no functionality built into
vue-test-utils
to select elements within a component based on$refs
and return them within a Wrapper. Our test suite is built around the idea that we can easily tag elements we need to hook onto within tests using$ref
rather than some arbitrary "marker class."I think it might be helpful to include a specific method on the wrapper like
findRefs
I'm not sure if this is a widely used strategy but we've found it helpful. Template structures change often and class selectors can easily break or target the wrong element when these changes happen.
The text was updated successfully, but these errors were encountered: