-
Notifications
You must be signed in to change notification settings - Fork 163
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
Vitest not able to mock OidcProvider #1510
Comments
In the end, I just removed the OidcProvider so my tests can run |
hi @Fraulk , for the moment i did not find a solution. I set up oidc component in higher component that I does not know how to test. |
This would be very interesting to know. I came up with the same solution as @Fraulk In case someone needs a working snippet here it is: // src/components/Providers/index.ts
import { OidcProvider, OidcSecure } from '@axa-fr/react-oidc'
import { HelmetProvider } from 'react-helmet-async'
import { config } from '@/common/config/oidc'
import { DesignSystemProvider } from './DesignSystemProvider'
import type React from 'react'
export interface ProvidersProps {
children: React.ReactNode
}
export function AppProviders({ children }: ProvidersProps) {
return (
// whatever other providers you need e.g. Redux
<HelmetProvider>
<OidcProvider configuration={config}>
<OidcSecure>
<DesignSystemProvider>{children}</DesignSystemProvider>
</OidcSecure>
</OidcProvider>
</HelmetProvider>
)
}
export default AppProviders
// src/components/Providers/test.ts
import { HelmetProvider } from 'react-helmet-async'
import { DesignSystemProvider } from './DesignSystemProvider'
import { ProvidersProps } from '.'
import type React from 'react'
export function TestProviders({ children }: ProvidersProps) {
return (
// same but without OidcProvider
<HelmetProvider>
<DesignSystemProvider>{children}</DesignSystemProvider>
</HelmetProvider>
)
}
export default Providers This way I can switch providers with import path: import Providers from '@/common/components/Providers' // AppProviders
import Providers from '@/common/components/Providers/test' // TestProviders However this would not help with setting up E2E tests because the app would break as soon as it encounters the first invocation of any It would be nice to know how to handle these scenarios, possibly without relying on features of external libraries. |
Hello, I replaced an oidc package with your project and it works perfectly, but it broke my test because of this error:
I also saw that issue #1343 and tried the mock the author did, but it now gives me another error:
The text was updated successfully, but these errors were encountered: