Skip to content

vue: Clarify what the return value of the callback param does in render #719

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

Merged
merged 2 commits into from
Dec 21, 2020

Conversation

lwkchan
Copy link
Contributor

@lwkchan lwkchan commented Dec 17, 2020

I'm currently learning vue-testing-library and had some trouble trying to set up vuex instance with simple-vuex. I found out elsewhere that a possible way to do this would be to use the callback parameter to return a store like the below

const store = createVuexStore(new RootStore())

// doesn't work because `createVuexStore(new RootStore())` is already an instance of `Vuex.Store`
render(MyComponent, {props: {happy: true}, store})

render(MyComponent, {props: {happy: true}}, () => ({ store }))

I think I could have noticed this sooner if the documentation described this line in the code: https://github.com/testing-library/vue-testing-library/blob/2312e180b12df3c599e8aa8a0ee85dcff7b108e7/src/vue-testing-library.js#L52. This is what i have tried to do in my proposed change above.

I'm currently learning vue-testing-library and had some trouble trying to set up `vuex` instance with `simple-vuex`. I found out elsewhere that the best way to do this would be to use the callback parameter to return a store like 
```tsx
const store = createVuexStore(new RootStore())

render(MyComponent, {props: {happy: true}}, () => ({ store }))
```

I think I could have noticed this sooner if the documentation described this line in the code: https://github.com/testing-library/vue-testing-library/blob/2312e180b12df3c599e8aa8a0ee85dcff7b108e7/src/vue-testing-library.js#L52. This is what i have tried to do in my proposed change above.
@eps1lon eps1lon changed the title Clarify what the return value of the callback param does in render vue: Clarify what the return value of the callback param does in render Dec 17, 2020
@eps1lon eps1lon requested a review from afontcu December 17, 2020 19:49
@afontcu
Copy link
Member

afontcu commented Dec 18, 2020

Hi! Thank you for this!

I agree that docs should explain how to the returned value for the callback function works (btw, there's an example test in the repo using vue-i18n).

However, I feel the addition could be improved a bit. Do you think you could rephrase it to explain that the callback function merges its return value back to the options? I wouldn't link to vue test utils to avoid confusion, and maybe link to the example test I shared above? Would that have helped you?

@lwkchan
Copy link
Contributor Author

lwkchan commented Dec 19, 2020

thank you for your feedback @afontcu. I agree that mentioning the merge would make it clearer. I think the vue-i18n example was where I saw that the store could be added in the callback, so I have included that link as well as you suggested 😄

Copy link
Member

@afontcu afontcu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 😃 thank you!

@nickserv nickserv merged commit aa31914 into testing-library:master Dec 21, 2020
@lwkchan lwkchan deleted the patch-2 branch March 13, 2021 00:34
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.

3 participants