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: allow passing instantiated Vuex store #232

Conversation

blimmer
Copy link
Contributor

@blimmer blimmer commented May 17, 2021

As currently written, the store property passed to the render function must be StoreOptions, which is a plain Javascript object passed to new Vuex.Store() in the render function.

This is great for simple components and should definitely still be a supported option. However, it would be really useful for us to be able to pass a complex, instantiated Vuex store (generated by our common test helpers) as well.

This PR accomplishes this behavior by checking if the passed store is an instance of Vuex.Store and skipping the new Vuex.Store() call in that case.

If this seems reasonable, I can also update the API documentation in the other repository 😄 . Thanks for your time & consideration!

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.

LGTM! Sorry for the late response, busy weeks. Merging this one once CI passes :)

@afontcu
Copy link
Member

afontcu commented Jun 14, 2021

Looks like there are some typing issues – probably due to the extended type for the store option? https://github.com/testing-library/vue-testing-library/pull/232/checks?check_run_id=2820969444#step:5:100

@blimmer blimmer force-pushed the feature/allow-passing-instantiated-store branch from 549c028 to 1159003 Compare June 15, 2021 22:32
@blimmer blimmer force-pushed the feature/allow-passing-instantiated-store branch from 04b47b4 to beddb67 Compare June 15, 2021 22:50
@blimmer
Copy link
Contributor Author

blimmer commented Jun 15, 2021

Thanks @afontcu - I updated this PR and tested it on my fork. I'm a little surprised that StoreOptions and Store are interchangeable but, if the test suite is working properly, it looks like they are!

@@ -127,6 +128,30 @@ export function testConfigCallback() {
})
}

export function testInstantiatedStore() {
render(SomeComponent, {
store: new Vuex.Store({
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 added this test to ensure that a Store could be provided as StoreOptions<S> and it looks like it works!

@codecov
Copy link

codecov bot commented Jun 25, 2021

Codecov Report

Merging #232 (789f889) into master (4efca8a) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #232   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           99        99           
  Branches        33        33           
=========================================
  Hits            99        99           
Impacted Files Coverage Δ
src/render.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4efca8a...789f889. Read the comment docs.

types/index.d.ts Outdated Show resolved Hide resolved
@afontcu afontcu merged commit 9d63d71 into testing-library:master Jun 25, 2021
@afontcu
Copy link
Member

afontcu commented Jun 25, 2021

Thank you for this! 🎉

@github-actions
Copy link

🎉 This PR is included in version 5.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Jun 8, 2022

🎉 This PR is included in version 6.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

None yet

2 participants