-
Notifications
You must be signed in to change notification settings - Fork 234
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
feat(find): allow chaining find with findComponent #897
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,22 +132,6 @@ export class VueWrapper<T extends ComponentPublicInstance> | |
return createWrapperError('DOMWrapper') | ||
} | ||
|
||
get<K extends keyof HTMLElementTagNameMap>( | ||
selector: K | ||
): Omit<DOMWrapper<HTMLElementTagNameMap[K]>, 'exists'> | ||
get<K extends keyof SVGElementTagNameMap>( | ||
selector: K | ||
): Omit<DOMWrapper<SVGElementTagNameMap[K]>, 'exists'> | ||
get<T extends Element>(selector: string): Omit<DOMWrapper<T>, 'exists'> | ||
get(selector: string): Omit<DOMWrapper<Element>, 'exists'> { | ||
const result = this.find(selector) | ||
if (result instanceof DOMWrapper) { | ||
return result | ||
} | ||
|
||
throw new Error(`Unable to get ${selector} within: ${this.html()}`) | ||
} | ||
|
||
findComponent<T extends ComponentPublicInstance>( | ||
selector: FindComponentSelector | (new () => T) | ||
): VueWrapper<T> { | ||
|
@@ -182,30 +166,7 @@ export class VueWrapper<T extends ComponentPublicInstance> | |
return createWrapperError('VueWrapper') | ||
} | ||
|
||
getComponent<T extends ComponentPublicInstance>( | ||
selector: FindComponentSelector | (new () => T) | ||
): Omit<VueWrapper<T>, 'exists'> { | ||
const result = this.findComponent(selector) | ||
|
||
if (result instanceof VueWrapper) { | ||
return result as VueWrapper<T> | ||
} | ||
|
||
let message = 'Unable to get ' | ||
if (typeof selector === 'string') { | ||
message += `component with selector ${selector}` | ||
} else if ('name' in selector) { | ||
message += `component with name ${selector.name}` | ||
} else if ('ref' in selector) { | ||
message += `component with ref ${selector.ref}` | ||
} else { | ||
message += 'specified component' | ||
} | ||
message += ` within: ${this.html()}` | ||
throw new Error(message) | ||
} | ||
|
||
findAllComponents(selector: FindAllComponentsSelector): VueWrapper<T>[] { | ||
findAllComponents(selector: FindAllComponentsSelector): VueWrapper<any>[] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced const wrapper = mount(Hello);
const cmps = wrapper.findAll(Foo); cmps was wrongly typed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh good catch! But There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely agree. I've opened separate issue #899 because I can't estimate effort to fix this properly, yet current PR has value - it is LESS wrong than previous version. |
||
if (typeof selector === 'string') { | ||
throw Error( | ||
'findAllComponents requires a Vue constructor or valid find object. If you are searching for DOM nodes, use `find` instead' | ||
|
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.
I really like how we set our expectations on both kind of wrappers (DOMWrapper & VueWrapper) by leveraging abstract methods