I am stuck at mock one of my React component because of using one translation library call 'react-simple-i18n'
In my React component, i need import one function from this library to use it as below :
import { useI18n } from 'react-simple-i18n/lib/'
const MyComponent = ({ data }) => {
const { t } = useI18n()
return(
<div>{t('MyComponent.hello') }</div>
)
}
and if i try to test with Jest (simple snapshot)
import React from 'react'
import { shallow } from 'enzyme'
import MyComponent from './MyComponent'
import { useI18n } from 'react-simple-i18n'
const fakeData = { ... }
jest.mock('react-simple-i18n', () => {
useI18n: () => { t: 'test' }
})
let wrapper = shallow(<MyComponent data={fakeData}/>)
describe('MyComponent', () => {
it('should render MyComponent correctly', () => {
expect(wrapper).toMatchSnapshot();
})
})
And i get a fail from Jest :
TypeError: Cannot destructure property
tof 'undefined' or 'null'.
How can i proprely mock my useI18n function ?