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: Add createStubs plugin hook #1241

Merged
merged 3 commits into from
Feb 7, 2022
Merged

feat: Add createStubs plugin hook #1241

merged 3 commits into from
Feb 7, 2022

Conversation

freakzlike
Copy link
Collaborator

Adds a new plugin API to config.plugins called createStubs which will override the default stub creation provided by VTU.

Usage:

config.plugins.createStubs = ({ name, component }) => {
  return defineComponent({
    render: () => h(`custom-${name}-stub`)
  })
}

When VTU creates a stub either from shallow: true or stubs: { ChildComponent: true }, then the provided function will be called.

This will allow to implement different custom logics which are mentioned here:

I have not updated the docs yet, but I will if it is good.

Closes #1216

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.

This might be a good idea. @lmiller1990 WDYT?

@lmiller1990
Copy link
Member

lmiller1990 commented Jan 26, 2022

Cool, but isn't this exactly the same as

import { config } from '@vue/test-utils'
config.globals.stubs = {
  // your stub
}

Maybe I did not read it properly or misunderstood - don't we already have the ability to create a stub globally like this?

Also, if we have a new feature, we should definitely document it, how it works, and why it's useful. This might also be useful for people reviewing it (like me :D )

@freakzlike
Copy link
Collaborator Author

Ok, I will add the docs soon :)

It is not used to stub one specific global component. Instead this will be called for all stubs so something similar like this:

import { config } from '@vue/test-utils'
config.globals.stubs = {
  '*': GlobalStub
}

Also the generated stub can by generic depending on the component which should be stubbed

@netlify
Copy link

netlify bot commented Jan 26, 2022

✔️ Deploy Preview for vue-test-utils-next-docs ready!

🔨 Explore the source changes: 1360c90

🔍 Inspect the deploy log: https://app.netlify.com/sites/vue-test-utils-next-docs/deploys/61f16bbd9ddbb90008bdf0fd

😎 Browse the preview: https://deploy-preview-1241--vue-test-utils-next-docs.netlify.app

@lmiller1990
Copy link
Member

I guess we can have this, although I'm not sure how much it'll be used.

I'd say this should be last feature before we move to 2.0 stable.

@lmiller1990 lmiller1990 merged commit 2abdbb8 into vuejs:main Feb 7, 2022
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.

Proposal: Hook to override default stub creation
3 participants