Skip to content

fix(#119): allow vue-router creation through routes param from both jest and mocha #127

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
Mar 17, 2020

Conversation

agualis
Copy link
Contributor

@agualis agualis commented Mar 13, 2020

This code fixes issue.

@@ -36,7 +36,7 @@ function render(
}

if (routes) {
const VueRouter = require('vue-router')
const VueRouter = require('vue-router') || require('vue-router').default
Copy link
Contributor Author

@agualis agualis Mar 13, 2020

Choose a reason for hiding this comment

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

The fix-code is ugly cause the problem is that in mocha unit tests we need to bundle the code with webpack (mocha-webpack) and that does not play well with using a require here.

The problem could be also solved with an async import (to follow ES6 notation) but that would probably make the code even uglier cause it would introduce async code.

Another workaround when using mocha, would be passing an already built router through router mounting option (instead of routes) but that cannot work be done with the current implementation.

Enabling this option for mocha users would be highly appreciated. Thanks for your awesome work!

@afontcu
Copy link
Member

afontcu commented Mar 15, 2020

Hi! Thanks for this! 😃

  • Is there a way to add some tests to make sure things are working as expected? I'm not well versed with mocha, but that would be great (right now CI pipeline is failing due to code coverage descending).

  • Should we do the same thing with Vuex?

@codecov
Copy link

codecov bot commented Mar 17, 2020

Codecov Report

Merging #127 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #127   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines          67     67           
  Branches       13     14    +1     
=====================================
  Hits           67     67
Impacted Files Coverage Δ
src/vue-testing-library.js 100% <100%> (ø) ⬆️

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 29e37dd...47168ef. Read the comment docs.

@agualis
Copy link
Contributor Author

agualis commented Mar 17, 2020

Is there a way to add some tests to make sure things are working as expected? I'm not well versed with mocha, but that would be great (right now CI pipeline is failing due to code coverage descending).

Some mocha tests could be added but that would not affect the code coverage as mocha does not use jest runner.

However, I just commited a hacky jest test (vue-router-mocha.js) that exercises the added code to keep the same coverage ( not the most expressive test though, I know 😅)

Should we do the same thing with Vuex?

No, we don't need it because vuex is built/exported in a different way than vue-router so that require works out of the box with mocha.

@afontcu
Copy link
Member

afontcu commented Mar 17, 2020

Looks good! I'm willing to merge this 🎉. Yet, do you have an external repository or something where we could see the fix actually fixing the issue? I've never used mocha, so I just want to make sure mocha is 100% usable after this 😄

@agualis
Copy link
Contributor Author

agualis commented Mar 17, 2020

Yet, do you have an external repository or something where we could see the fix actually fixing the issue?

The repository pointing the issue (#119) reproduces the error with this mocha test

@afontcu If you replace vue-testing-library with the code in current PR, that test will ✅ 😊

UPDATE: I double checked that repo and It seems that I lied 😅 as the linked repo did not have a correct chai setup. I quickly fixed it in this fork.

@agualis
Copy link
Contributor Author

agualis commented Mar 17, 2020

BTW, I prefer jest over mocha but it need to use it in a legacy project. I think that I could help to mimic vue-testing-library examples in mocha but I would suggest to do it in the official vue-testing-library repository so it's easier to find/maintain them.

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.

Sure, let's go with this! Since I won't be using mocha, feel free to keep submitting PRs if you run into similar issues 😄

Thanks for this!

@afontcu afontcu merged commit 58a4b5a into testing-library:master Mar 17, 2020
@afontcu
Copy link
Member

afontcu commented Mar 17, 2020

🎉 This PR is included in version 5.0.1 🎉

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.

Vue router configuration not working with mocha-chai
2 participants