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
Support find({ ref })
syntax
#716
Comments
The issue is that VTU is expecting Since this is perfectly valid use case, I believe a perfect solution is to add assertion there and throw in case of such scenario as first step. After that allow |
Adding a user-friendly exception there sounds a good first step. @kanryu fancy to open up a PR? 🚀 |
I don't understand how this can be considered a valid use case.
This seems like the correct behavior. If this was to be supported, it would be a new feature, and it would be I agree the error message is indeed very confusing. We should definitely fix that. I'd expect |
@lmiller1990 Sorry, I needed to explain my "perfectly valid use case" - I was meaning that "it is perfectly valid use case to assign ref to DOM node in Vue". I totally support your position about error message and that |
I understand now - thanks. I see two actions here:
|
@lmiller1990 , I see the PR for the first action item you mentioned has been merged and will probably be released soon. Any idea when the second option (finding DOM nodes via ref, like VTU1 did) will see traction? I have numerous unit tests written for Vue 2 that utilize refs on DOM nodes, and converting them to Vue 3 would be a lot smoother with just that one addition. The example used for this issue, rewritten with |
I think we could have this to help migration, but I don't think this should be a main feature or recommended way to query DOM nodes moving forward. I'd generally recommend things that work with Unless you number of tests is truly staggering, it's probably just faster to change them all from In the meantime, if you want this now, you could try creating a plugin: https://next.vue-test-utils.vuejs.org/guide/extending-vtu/plugins.html#plugins. All the DOM traversing logic is here, we could expose some of the those functions if you need them. This feature could definitely be built in user land. As for gaining traction, if enough people request the feature, we can definitely reconsider, but it seems like querying a DOM node by |
Personally, I think it would be really great to be able to find HTML elements by ref. I prefer this because I don't end up adding extra data to the dom that are purely used for my unit testing purposes. |
I am currently working on migrating our project to vue 3 and have about 400 tests that fail because I can't find dom elements by ref. I would love for this to be re-added |
While we figure out how to implement this in a way that covers all edge cases, I will try to provide a method you can use in the mean-time to help with migration. |
@lmiller1990 Any progress on a method we ca use to help with migration? |
Yes, https://github.com/vuejs/vue-test-utils-next/releases/tag/v2.0.0-rc.16 was released, I don't think we have support for |
Sorry for the somewhat-wordy response, but I want to make a few points. Unfortunately, your reference to I have always considered CSS selectors as being used for presentation, and if I really need a unit test to verify an element exists, assigning it a Imagine scenarios like "Testing cancel and submit buttons in a modal" or "Testing input B when input A has a certain value"
One additional limitation I have encountered using CSS selectors comes up when using LESS as your CSS preprocessor. In the Vue 2 version using I feel this should be re-added to core, but if that's not possible, a helper migration method would be amazing. A plugin would work as well, and I won't exclude that as a possibility. I do think, however, that the points I've made here illustrate that more thought needs to be given to a proper solution. |
find({ ref })
syntax
Right, I understand now - the original issue title and discussion were completely different. I changed the issue title. I forgot the context of why support for this was dropped. I can look into it again... if anyone else wants to speed things up, happy to help out with code review. Since we already have find by ref for |
Coming in #1094 |
Thank you to everyone involved! :) |
Subject of the issue
Calling findComponent () with the ref method causes a run-time error.
Steps to reproduce
wrapper.findComponent({ref: 'some_ref'})
Expected behaviour
findComponent() should return a valid node.
Actual behaviour
runtime error.
Possible Solution
I can't comment because I don't know the detailed implementation of this framework, but when I checked it with the debugger,
VueWrapper.prototype.attachNativeEventListener()
is executed twice.The first time,
vm
points to a Proxy and it runs success.The second time it points to a HTMLButtonElement and it doesn't have a
$options
property, which causes a run-time error.versions
The text was updated successfully, but these errors were encountered: