-
Notifications
You must be signed in to change notification settings - Fork 244
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
WIP: detect multiple root nodes #25
Conversation
return Array.from(results).map((x) => new DOMWrapper(x)) | ||
} | ||
|
||
async setChecked(checked: boolean = true) { | ||
return new DOMWrapper(this.vm.$el).setChecked(checked) | ||
return new DOMWrapper(this.element).setChecked(checked) |
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.
Here it would probably be best to return an error, if the component has multiple roots?
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.
as discussed I think we should omit this code entirely for now and revisit it later - setChecked
on a VueWrapper may not make sense after all, I am in favor of only supporting it on DOMWrapper.
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.
OK. We can add them back later I guess.
} | ||
|
||
trigger(eventString: string) { | ||
const rootElementWrapper = new DOMWrapper(this.vm.$el) | ||
const rootElementWrapper = new DOMWrapper(this.element) |
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.
Here it would probably be best to return an error, if the component has multiple roots?
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.
See above!
src/vue-wrapper.ts
Outdated
@@ -26,15 +43,15 @@ export class VueWrapper implements WrapperAPI { | |||
} | |||
|
|||
html() { | |||
return this.vm.$el.outerHTML | |||
return this.element.outerHTML |
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.
We can probably do innerHtml
for multiple root nodes?
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.
what does outer html return? Whatever makes most sense!
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.
outerHtml
returns the mount point, which is in this case div#app
:/
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.
sure, makes sense. I think we need outerHTML for a single node still? (not sure)
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.
Correct. It will be a check for multiRoot
src/vue-wrapper.ts
Outdated
this.componentVM.$el.parentElement | ||
: this.componentVM.$el | ||
} | ||
|
||
classes(): string[] { | ||
throw Error('TODO: Implement VueWrapper#classes') |
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.
We should error out if classes is used with multiple nodes.
Some interesting stuff here. Before getting to into a code review, I have some thoughts:
I'm starting to think we should support Take two cases: Case 1: <template>
<input id="foo" type="checkbox" />
</template> Case 2: <template>
<input id="foo" type="checkbox" />
<input id="bar" type="checkbox" />
</template> Case 1 Should we just remove Case 1: It's the same for both. Then the user does not need to think about how many root nodes there are, and we don't need to deal with the complexity. You just find your DOM element, and call Thoughts? @afontcu and @dobromir-hristov ? |
As most of the times, we just invoke the DOMWrapper methods, it makes sense to remove it from the VueWrapper. As for |
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.
Left some minor comments, mainly around private
on the hasMultipleRoots
src/vue-wrapper.ts
Outdated
this.__emitted = events | ||
} | ||
|
||
get __hasMultipleRoots(): boolean { |
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.
instead of using __
we can just make this private
and it will only be accessible in the class (and you don't need __
anymore)
private get hasMultipleRoots(): boolean
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.
alright then
src/vue-wrapper.ts
Outdated
@@ -26,15 +43,15 @@ export class VueWrapper implements WrapperAPI { | |||
} | |||
|
|||
html() { | |||
return this.vm.$el.outerHTML | |||
return this.element.outerHTML |
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.
sure, makes sense. I think we need outerHTML for a single node still? (not sure)
return Array.from(results).map((x) => new DOMWrapper(x)) | ||
} | ||
|
||
async setChecked(checked: boolean = true) { | ||
return new DOMWrapper(this.vm.$el).setChecked(checked) | ||
return new DOMWrapper(this.element).setChecked(checked) |
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.
as discussed I think we should omit this code entirely for now and revisit it later - setChecked
on a VueWrapper may not make sense after all, I am in favor of only supporting it on DOMWrapper.
} | ||
|
||
trigger(eventString: string) { | ||
const rootElementWrapper = new DOMWrapper(this.vm.$el) | ||
const rootElementWrapper = new DOMWrapper(this.element) |
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.
See above!
8e05ee4
to
ccb460b
Compare
We can remove the other methods in another PR. |
learned a lot from this PR about internals of Vue 3, great! |
Description
This PR finds the component's component instance inside the mounted parent vm.
Then adds a property to note if it has multiple root nodes.
This should be then used to aid methods like
find
orclasses
as they cannot work with multiple root nodes as of now.Related to #19
What next?
I need to check whether we can do the same queries from the component's own element, not the mounting parent, even though they should be the same.
Fine Print
This took allot of digging, but I finally got the hang of things 😆