-
Notifications
You must be signed in to change notification settings - Fork 668
Update find
and findAll
to be more robust
#681
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
Conversation
try { | ||
document.querySelector(selector) | ||
return true | ||
|
||
const pseudoSelectors = ['.', '#', '[', ':', '>', ' '] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite ugly but needed to cover all existing test cases:
find("#id")
find(".class")
find("div")
html elementfind("text")
svg element- `find("div > p") pseudo selector, although this is prob bad practise in tests anyway
find("p:first-of-type")
"lodash": "^4.17.4" | ||
"html-tags": "^2.0.0", | ||
"lodash": "^4.17.4", | ||
"svg-elements": "^1.0.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both libs are just json lists. an alternative would be just copy paste the json lists into the project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO,
Since their size is small,
I think it is not necessary to use library.
Vue.js
does not use the library as below.
https://github.com/vuejs/vue/blob/f76d16ed9507d4c2a90243ea3d77ccf00df29346/src/platforms/web/util/element.js#L11-L32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I agree. Just going to grab the list from vuejs/vue repo.
find
and findAll
to be more robustfind
and findAll
to be more robust
All green! Might have missed some edges cases, but looking good. |
@eddyerburgh @38elements Should be okay to review now, CI finished, all green. Thanks. |
Sorry I don't think I made my intentions with this clear. I don't think this should be an alias for name. I think this should work as a tag selector for components: const SomeComp = {
name: 'a-name'
}
const TestComponent = {
template: '<div><some-comp /></div>',
components: {SomeComp}
}
const wrapper = mount(TestComponent)
wrapper.find('a-name').exists() // false
wrapper.find('some-comp').exists() // true
wrapper.find('SomeComp').exists() // false
wrapper.find({name: 'a-name'}).exists() // true As @38elements suggested, we already have a name selector that's explicit. |
Maybe I misunderstood. Let me check my new understanding: Instead of writing the logic where I did (in isNameSelector and vmMatchCtorName) I should have a isTagSelector and vmMatchTag? If that is the case it’s a matter of moving things around. I’ll wait for your confirmation first. Thanks. |
Yes. Or have an VM_TAG_SELECTOR const, and then use that to get a vm and match its tag. For instances you need to check the I'm not sure about functional components, I think |
I can not understand this pull request comment and state. #651 is an issue which is feature request for IMHO, |
@eddyerburgh Thanks for the clarification, I can work on it tomorrow. It makes sense to not add this logic where I did, but in a @38elements Proposal 1) add <template>
<hello>
</template> I want to assert
I think it's a little unintuitive. I need to specify
I want to be able to write this style of assertion in Once implemented, the API will be like this: import { shallowMount } from "@vue/test-utils"
const wrapper = shallowMount(Component)
expect(Component.find("hello").exists()).toBe(true) Does that make sense? There was also another issue discussed, which is rendering the contents of a default slot. That is another issue, #658 , and as you said, should be addressed in a separate PR. |
@eddyerburgh @lmiller1990 |
No, it does not. |
Ok, we should split this PR out into two issues and continue discussion there:
|
@eddyerburgh |
New PR for this feature is here: #692 Please review and continue discussion there. |
See #651 for details of the goal of this PR.
WIP. Some failing tests to fix, then add some for the new feature.
The general idea I'm going with at the moment:
Change
validators/isDomSelector
to only work on "real" dom elements. This includes the following cases:div
,span
"#id"1,
".class"`p:second
text
With that change,
isNameSelector
will catch any other strings, likeMyElement
And add some tests. I am part way through updating
isDomSelector
, 4 failing tests remain. The approach isn't that nice - anyone has a better way, please let me know. The main complexity is differentiating:If we had a hard rule on custom component names to be either camelcase or kebabcase, we could use that logic, however I'm sure some people will have single word components, like
<poster>
.We should also render contents of default slot by in
mountShallow
, this might be okay in a separate PR to keep things easy to review. One of my coworkers is keen on his first contribution, maybe can leave that one for him. First contribution to OSS is always challenging.