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: include the mocks in component globalThis #2120

Closed
wants to merge 3 commits into from

Conversation

jrutila
Copy link

@jrutila jrutila commented Jul 3, 2023

In the components beforeCreate we include all the mocks also in globalThis. That way the mocks are usable also in the script setup part of the component.

This PR contains the unit test and the solution.

Fixes #2119

@netlify
Copy link

netlify bot commented Jul 3, 2023

Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit e6d0241
🔍 Latest deploy log https://app.netlify.com/sites/vue-test-utils-docs/deploys/64a3117beb8f9a000891b2d8
😎 Deploy Preview https://deploy-preview-2120--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -228,6 +228,8 @@ export function createInstance(
this.$.setupState[k] = v
// eslint-disable-next-line no-empty
} catch (e) {}
//@ts-ignore Setting an unknown global variable for the component instance
globalThis[k] = v
Copy link
Member

Choose a reason for hiding this comment

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

Did this work in Test Utils v1? I actually am surprised this doesn't "just work".

Copy link
Member

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Any chance we can add a few more tests around the various globals from Nuxt? I believe they also inject components and a few other things? cc @jrutila

@jrutila
Copy link
Author

jrutila commented Aug 21, 2023

Any chance we can add a few more tests around the various globals from Nuxt? I believe they also inject components and a few other things? cc @jrutila

Good point. Nuxt injects through auto imports components. I see if I manage to add that case, too.

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.

Feature request: global.mocks to also mock into the script setup, not just the template
2 participants