-
Notifications
You must be signed in to change notification settings - Fork 100
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
help: Plugins Inject Unit Test #576
Comments
I would mock the return value of To mock it when it's used as a global: const useContextMock: Mock<any, any> = vi.fn().mockImplementation(() => {
return { $myFunc: (str: string) => str }
})
vi.stubGlobal('useContext', useContextMock)
// And to change the implementation for a specific test
useContextMock.mockImplementation(() => {
return { $myFunc: (str: string) => `Changed - ${str}` }
}) To mock it when it's imported directly: import { useContext } from '@nuxtjs/composition-api'
vi.mock('@nuxtjs/composition-api', () => {
return {
useContext: vi.fn().mockImplementation(() => {
return { $myFunc: (str: string) => str }
}),
}
})
// And to change the implementation for a specific test
vi.mocked(useContext).mockImplementation(() => {
return { $myFunc: (str: string) => `Changed - ${str}` }
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
馃摎 What are you trying to do? Please describe.
Hi,
how to mock injection?
injection was working fine, but its become undefined when running test.
Nuxt2 + Typescript + CompositionApi
馃攳 What have you tried?
Have mocks in options, still not works.
鈩癸笍 Additional context
The text was updated successfully, but these errors were encountered: