You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! What is the recommended way to set up unit tests with components that use next-translate?
I currently don't see a straightforward way of doing this, so I concocted my own solution (albiet imperfect). Right now I'm creating a custom render function when using testing-library/react. In that, I use I18nProvider then pass in any translations I think it might need, but this can get unwieldy since this would require me to know all the translations my tests will need upfront.
// testUtils.tsximportReactfrom'react'import{render}from'@testing-library/react'importI18nProviderfrom'next-translate/I18nProvider'importindexfrom'locales/en/index.json'constProviders: React.FC=({ children })=>(<I18nProviderlang="en"namespaces={{ index }}>{children}</I18nProvider>)// eslint-disable-next-line @typescript-eslint/no-explicit-anyconstcustomRender: typeofrender=((ui: any,options: any)=>render(ui,{wrapper: Providers, ...options}))asunknownastypeofrenderexport*from'@testing-library/react'export{customRenderasrender}
In the test, I'm trying to use getT to get the translation being used, but I get the following error:
Is there a recomended way of going about this?
Thanks
Hello! What is the recommended way to set up unit tests with components that use
next-translate
?I currently don't see a straightforward way of doing this, so I concocted my own solution (albiet imperfect). Right now I'm creating a custom
render
function when usingtesting-library/react
. In that, I useI18nProvider
then pass in any translations I think it might need, but this can get unwieldy since this would require me to know all the translations my tests will need upfront.In the test, I'm trying to use
getT
to get the translation being used, but I get the following error:Is there a recomended way of going about this?
Thanks
Edit: turns out this is also an open question on stack overflow
The text was updated successfully, but these errors were encountered: