I have 2 versions of the same code, one works, one throws:
TypeError: axios.get.mockResolvedValue is not a function
Works:
const axios = require('axios')
jest.mock('axios') //<<<------
test('should mock axios', async () => {
const resp = {data: {moreData: 'zedata'}}
axios.get.mockResolvedValue(resp)
const actualresp = await getAxios()
expect(actualresp).toEqual({moreData: 'zedata'})
})
Doesn't:
const axios = require('axios')
test('should mock axios', async () => {
jest.mock('axios') //<<<------
const resp = {data: {moreData: 'zedata'}}
axios.get.mockResolvedValue(resp)
const actualresp = await getAxios()
expect(actualresp).toEqual({moreData: 'zedata'})
})
Can someone help me understand why moving jest.mock('axios') inside the testblock (or inside any function, for that matter) results in an error?