-
Notifications
You must be signed in to change notification settings - Fork 668
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: Store selector in Wrapper.find() / .findAll() #1248
feat: Store selector in Wrapper.find() / .findAll() #1248
Conversation
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 believe most of it is done but I'd like to add some more tests here.
return selector.value | ||
} | ||
|
||
return 'Component' |
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 believe that we could use the component name at least in some cases here. However I'd like to keep that as a follow-up.
@eddyerburgh Can you please take a look? |
Thanks, look great. Before we merge can you update the type definition for Wrapper? |
@eddyerburgh I'm sorry, I'm not completely sure what you mean by that. 😓 The flow definition has already been updated: https://github.com/vuejs/vue-test-utils/pull/1248/files#diff-dff4d7307e5e694d79396aacecd4399e Do I need to update anything else, too? |
ah, I think I found what you were referring to: https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/types/index.d.ts I will update that file in a bit. 👍 |
@eddyerburgh Can you please take another look here? |
@eddyerburgh Any chance to get this merged? |
@@ -69,6 +69,7 @@ interface BaseWrapper { | |||
|
|||
trigger (eventName: string, options?: object): void | |||
destroy (): void | |||
selector: Selector | void |
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.
This isn't actually a Selector type, it's an object with a value and type: https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/get-selector.js#L38
Because the library isn't written in TS, we have tests (https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/types/test/wrapper.ts) that access and set the wrapper options using the types. Can you write a test that accesses selector.value and selector.type and update this types file.
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.
This isn't actually a Selector type
@eddyerburgh Thank you for catching this! 👍
It actually is of type Selector for the ErrorWrapper:
this.selector = selector |
I will update the other places to use rawSelector
(which is of type Selector), too, because that prevents us from defining a new type and consumers of the API don't need to do selector.value
to get the selector they provided in the first place.
we have tests (https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/types/test/wrapper.ts)
Sure, I can add tests there! 👍
Right now I'm a little confused by the structure of that file though because it has neither test cases in the usual style (no it('something happens', () => { ... })
/ test(...)
blocks) nor assertions (only implicit ones). Could you provide me with an example of how such a test would look like?
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.
It actually is of type Selector for the ErrorWrapper:
Ah, it turns out this was wrong actually—but the Selector type is currently any
:
vue-test-utils/flow/wrapper.flow.js
Line 6 in 70ac83a
declare type Selector = any |
I will adjust the places that create ErrorWrapper instances to use the rawSelector as well then.
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, the test script just compiles the file to make sure there aren't any compiler errors when using the Vue Test Utils API, caused by incorrect typing.
A test would look something like this:
let s: string = wrapper.selector.value
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.
Thanks! 🙇♂️ I'll add the tests and ping you again once they are ready.
@eddyerburgh I have updated all places to output the rawSelector (that is passed to Can you please have another look at this? |
@eddyerburgh Please let me know if there is anything I can do to get this finished. I would love to work on the other contributions that depend on this. |
Hi @winniehell thank you for the great work! Hoping to get this merged shortly. |
Nice addition! Looks like the PR has some conflicts with master, would you have the time to fix them? Thanks for your patience! Hopefully we will land this soon :) |
@afontcu done ✔️ |
Hey @winniehell, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚 |
Thank you @JessicaSachs! 🙇♂️ |
Stores the selector that is passed to
Wrapper.find()
/Wrapper.findAll()
as a property in the newly createdWrapper
/WrapperArray
instance.closes #1135