-
Notifications
You must be signed in to change notification settings - Fork 672
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
Unable to mock lifecycle hooks #166
Comments
I don't think we're going to go ahead with this, as we want to avoid editing the internals. Thanks for the PR though 🙂 |
This not work for me =( |
const mixin = {
beforeCreate() {
// do something
}
}
mount(TestComponent, {
mixins: [mixin]
}) Or using const mixin = {
beforeCreate() {
// do something
}
}
localVue = createLocalVue()
localVue.mixin(mixin)
mount(TestComponent, {
localVue
}) |
But mixins for hooks don't get overridden , they got merged and both hook will be called, so this won't work |
Thanks, @aldarund ! Yes, this is a very important point. |
To add to this, One of my components has,
How can I get around this when the only thing I need to do for this component is create a snapshot? |
I've tried a really hacky work-around:
|
Got a sample snippet @z0gSh1u? |
Imho adding this feature will make vue-test-utils really, really powerful as you will be able to decouple dependencies/globals/or what have you from the components and mock them normally. This is most useful in Nuxt with loads of modules. |
You can just use lodash merge, to overwrite the hook, before you mount it. Ofc that won't work for |
@dobromir-hristov, I'll try. As I said, my use case is that I have a Nuxt module, $recaptcha in this case, that is called on |
How about spying on and overriding the implementation before mounting?
|
@antman888 thanks bro. that's what i'm looking for. |
What problem does this feature solve?
The test author is currently not able to remove the lifecycle-hook implementation from components. The hooks are:
What does the proposed API look like?
The Mock Object in the
options
object can be used:The text was updated successfully, but these errors were encountered: