-
Notifications
You must be signed in to change notification settings - Fork 264
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
fix: stubbing RouterLink #438
Conversation
@@ -1,5 +1,6 @@ | |||
import { defineComponent } from 'vue' | |||
import { mount } from '../src' | |||
import { mount, MountingOptions, RouterLinkStub, shallowMount } from '../src' | |||
import Issue425 from './components/Issue425.vue' |
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 love this idea
src/mount.ts
Outdated
!['transition', 'transition-group'].includes(name) | ||
) { | ||
app.component(name, stub) | ||
} |
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.
Can't we simply register the stub with the provided key in stubs? That's what we do for components (and I realize that's why I used this in my apps instead of stubs) and it should work fine?
Something like (untested):
for (const [name, stub] of Object.entries(global.stubs)) {
if (stub === true) {
// default stub.
app.component(name, createStub({ name, props: {} }))
} else {
// user has provided a custom implementation.
app.component(name, stub)
}
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.
That is what I thought, but it was not working - seems there is something else at work here 🤔
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.
See comment below - I think we can just pascal case everything and it will "just work"
src/mount.ts
Outdated
// ref: https://github.com/vuejs/vue-test-utils-next/issues/249 | ||
// we register both the hyphenated version and non-hyphenated | ||
// version for good measure. | ||
// ref: https://github.com/vuejs/vue-test-utils-next/issues/425 | ||
if (global?.stubs) { | ||
for (const [name, stub] of Object.entries(global.stubs)) { | ||
const tag = hyphenate(name) |
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.
IIRC, when a component is registered in PascalCase, it works in the template regardless of whether the template uses kebab-case or PascalCase. maybe we could solve this without double registration by replacing this with a toPascalCase()
?
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.
Hmm neat idea, I will give this a try
Co-authored-by: Alex Van Liew <[email protected]>
Question: how does |
That flag can force the default slot to be rendered. There is an example documented here (note the It looks like if you use |
…utils-next into fix-stubbing-router-link
Fixed, I just removed |
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.
That's what I had in mind 👍
There is a comment that needs to be fixed.
And it would be great to squash all this into a single commit before merging 😉
Co-authored-by: Alex Van Liew <[email protected]>
@cexbrayat added the comment thanks to @snoozbuster. I will use the squash/merge feature on GH to squash all the commits. |
It's merged. I will probably do a release this weekend, we should get a few more things fixed by then. Thanks all! |
@lmiller1990 could we release sooner than this weekend? some of the tests I am trying to write are getting stuck on this issue, and I don't want to put in a workaround that I know I will have to come back and fix very soon. |
Alright, please wait for 24 hours or so. |
resolves #425
Not sure if this ideal, pretty messy but this is one way to fix the problem. 🤔 hyphenating stubs by default messes things up.