Im using Jest / enzyme to test react components and having some trouble getting my mock function to actually get used:
The file I am testing
export const myFunction = () => {}
const MyComponent = () => {
return <> {myFunction()} </>
}
export default MyComponent
My test file
import MyComponent, {myFunction} from 'myFile.jsx'
jest.mock('myFile.jsx', () => ({
__esModule: true,
...requireActual('myFile.jsx'),
myFunction: jest.fn()
}))
// then a test
it('test', () => {
myFunction.mockReturnValue('one') // this never gets mocked when I call the component
...mountComponent
log( myFunction.mock.calls.length) // 0
})
So as you can see the mocks are working however the actual mock function is not getting called. Anyone have any ideas about what could cause this?