-
Notifications
You must be signed in to change notification settings - Fork 277
issue-249 feat: stub global components #260
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { h, ComponentOptions } from 'vue' | ||
| import { h, ComponentOptions, defineComponent } from 'vue' | ||
|
|
||
| import { config, mount } from '../../src' | ||
| import { config, mount, RouterLinkStub } from '../../src' | ||
| import Hello from '../components/Hello.vue' | ||
| import ComponentWithoutName from '../components/ComponentWithoutName.vue' | ||
| import ComponentWithSlots from '../components/ComponentWithSlots.vue' | ||
|
|
@@ -37,6 +37,31 @@ describe('mounting options: stubs', () => { | |
| expect(wrapper.html()).toBe('<div></div><foo-stub></foo-stub>') | ||
| }) | ||
|
|
||
| // https://github.com/vuejs/vue-test-utils-next/issues/249 | ||
| it('applies stubs globally', () => { | ||
| const Comp = defineComponent({ | ||
| template: '<div><foo /><router-link to="/foo" /><router-view /></div>' | ||
| }) | ||
| const wrapper = mount(Comp, { | ||
| global: { | ||
| stubs: { | ||
| Foo: true, | ||
| RouterLink: RouterLinkStub, | ||
| RouterView: defineComponent({ | ||
| render() { | ||
| return h('span') | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| expect(wrapper.html()).toBe( | ||
| '<div><foo-stub></foo-stub><a></a><span></span></div>' | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I'm a bit unclear on how everything is related, can you maybe add a test where we try to find the component registered as a stub? I'd like to be sure that I think a real use-case would be to stub
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: 20c7694 Is this what you mean?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect, thanks Lachlan!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, want to give me a big old ✅ |
||
| expect(wrapper.getComponent(RouterLinkStub).vm.to).toBe('/foo') | ||
| }) | ||
|
|
||
| it('stubs a functional component by its variable declaration name', () => { | ||
| const FunctionalFoo = (props) => h('p', props, 'Foo Text') | ||
|
|
||
|
|
||
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.
It is possible to use router-link
<router-link />(however unlikely)