Here is a simplified version of both my function and test. Although I mocked the useTranslation I get the following error:
You are passing an undefined module! Please check the object you are passing to i18next.use()
7 | i18n 8 | .use(Backend) > 9 | .use(initReactI18next)
How do I properly mock to get rid of this error?
import React from 'react'
import { useTranslation } from 'react-i18next'
import * as Constants from 'constants'
import MyComponent from 'components'
const Dashboard = () => {
const { t } = useTranslation('dashboard')
return (
<div> Dashboard
<MyComponent name={t(Constants.MYCOMPONENT)}/>
</div>
)
}
export default Dashboard
jest.mock('react-i18next', () => ({
useTranslation: () => ({ t: (key) => key })
}))
it('Render Dashboard without crash', () => {
const div = document.createElement('div')
ReactDOM.render(<Dashboard/>, div)
})