Skip to content
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

Merged
merged 5 commits into from
Dec 18, 2019
Merged

feat: Store selector in Wrapper.find() / .findAll() #1248

merged 5 commits into from
Dec 18, 2019

Conversation

winniehell
Copy link
Contributor

@winniehell winniehell commented May 30, 2019

Stores the selector that is passed to Wrapper.find() / Wrapper.findAll() as a property in the newly created Wrapper / WrapperArray instance.

closes #1135

Copy link
Contributor Author

@winniehell winniehell left a 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'
Copy link
Contributor Author

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.

packages/test-utils/src/error-wrapper.js Outdated Show resolved Hide resolved
packages/test-utils/src/wrapper.js Outdated Show resolved Hide resolved
@winniehell winniehell changed the title WIP: feat: Store selector in Wrapper.find() / .findAll() feat: Store selector in Wrapper.find() / .findAll() May 31, 2019
@winniehell
Copy link
Contributor Author

@eddyerburgh Can you please take a look?

@eddyerburgh
Copy link
Member

Thanks, look great. Before we merge can you update the type definition for Wrapper?

@winniehell
Copy link
Contributor Author

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?

@winniehell
Copy link
Contributor Author

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. 👍

@ghost
Copy link

ghost commented Jun 27, 2019

@eddyerburgh Can you please take another look here?

@winniehell
Copy link
Contributor Author

@eddyerburgh Any chance to get this merged?

@@ -69,6 +69,7 @@ interface BaseWrapper {

trigger (eventName: string, options?: object): void
destroy (): void
selector: Selector | void
Copy link
Member

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.

Copy link
Contributor Author

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:

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?

Copy link
Contributor Author

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:

declare type Selector = any

I will adjust the places that create ErrorWrapper instances to use the rawSelector as well then.

Copy link
Member

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

Copy link
Contributor Author

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.

@winniehell
Copy link
Contributor Author

@eddyerburgh I have updated all places to output the rawSelector (that is passed to find / findAll), added some TypeScript tests, and CI is still green. 🍏 🎉

Can you please have another look at this?

@winniehell
Copy link
Contributor Author

@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.

@JessicaSachs
Copy link
Collaborator

Hi @winniehell thank you for the great work! Hoping to get this merged shortly.

@afontcu
Copy link
Member

afontcu commented Dec 15, 2019

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 :)

@winniehell
Copy link
Contributor Author

@afontcu done ✔️

@JessicaSachs JessicaSachs merged commit 7c7b949 into vuejs:dev Dec 18, 2019
@vue-bot
Copy link

vue-bot commented Dec 18, 2019

Hey @winniehell, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚

@winniehell winniehell deleted the winniehell-wrapper-selector branch December 18, 2019 20:56
@winniehell
Copy link
Contributor Author

Thank you @JessicaSachs! 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Always store selector in Wrapper created by wrapper.find(...)
5 participants