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

issue-249 feat: stub global components #260

Merged
merged 3 commits into from
Nov 24, 2020
Merged

issue-249 feat: stub global components #260

merged 3 commits into from
Nov 24, 2020

Conversation

lmiller1990
Copy link
Member

Maybe @cyberb can have some input here too.

This addresses #249

At the moment stubs will only work for locally registered components. For global ones (like <router-link>) you currently must registered a component globally to stub it, eg:

mount(Foo, {
  components: {
    RouterLink: {
     render() { return h('div') }
    }
  }     
})

Many people expect this to work (I also do)

mount(Foo, {
  global: {
    stubs: {
      RouterLink: {
       render() { return h('div') }
      }
    }
  }     
})

This PR takes anything from global.stubs and registers a global stub.

Copy link
Member

@cexbrayat cexbrayat left a comment

Choose a reason for hiding this comment

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

I think it makes sense to move in that direction, it felt weird to write components: { RouterLink: RouterLinkStub } in tests 👍

That now leaves the question: do we need to keep components if we can do the same with stubs? But maybe we can't and I'm missing something.


expect(wrapper.html()).toBe(
'<div><router-link-stub></router-link-stub><span></span></div>'
)
Copy link
Member

@cexbrayat cexbrayat Nov 24, 2020

Choose a reason for hiding this comment

The 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 getComponent and friends work in that case as well.

I think a real use-case would be to stub RouterLink with RouterLinkStub, find it, and check its props to see if the component is creating links with the appropriate values. So I'd like to make sure we cover this 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea

Copy link
Member Author

Choose a reason for hiding this comment

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

Done: 20c7694

Is this what you mean?

Copy link
Member

Choose a reason for hiding this comment

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

Perfect, thanks Lachlan!

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, want to give me a big old ✅

@lmiller1990
Copy link
Member Author

lmiller1990 commented Nov 24, 2020

@cexbrayat the global components option probably isn't really useful. That said, global is supposedmirro what you can do with app, eg app.component, app.mixin etc, so I think it's okay to have it. I don't expect people to use it, though (how often does someone register a global component? Only libs like Vuetify and that sort of thing, I guess).

@@ -12,6 +12,6 @@ export const RouterLinkStub = defineComponent({
},

render() {
return h('a', undefined, this.$slots.default())
return h('a', undefined, this.$slots?.default?.())
Copy link
Member Author

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)

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.

None yet

2 participants