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

Mock an Injected object #601

Closed
khawarizmus opened this issue Oct 23, 2023 · 2 comments
Closed

Mock an Injected object #601

khawarizmus opened this issue Oct 23, 2023 · 2 comments

Comments

@khawarizmus
Copy link

As I am currently using the Provide / Inject feature, I am wondering how to go about mocking the injected object, example in my code I have:

// in dashboard.vue

const { error, data } = await settingsStore.refreshRemoteSettings(); // we refresh the user settings state
provide(REMOTE_SETTINGS, data);

// in my composable
const settings = inject(REMOTE_SETTINGS);

is there a way to achieve this currently with Viteest? and can we have a helper like mockInject or mockProvide ?

@Ciscodefran
Copy link

Ciscodefran commented Nov 30, 2023

Put this into your code.

const { vueApp } = useNuxtApp()
vueApp._context.provides =  {
  ...vueApp._context.providers,
  REMOTE_SETTINGS: () => { your config }
}

@danielroe danielroe transferred this issue from danielroe/nuxt-vitest Dec 2, 2023
@danielroe
Copy link
Member

let's track in #539

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants