jest-fetch-mock
jest-fetch-mock copied to clipboard
[Question] - Configure the headers globally with json content-type.
Is it possible to configure the headers globally with the default value as { headers: { 'content-type': 'application/json' }}?
Currently everytime I try to do a mockResponseOnce it set the default header as 'Content-Type': [ 'text/plain;charset=UTF-8' ] by default, and I don't want to pass the headers to every mockResponseOnce calls as I don't have requests that return text/plain content:
require('jest-fetch-mock').enableMocks()
...
describe('example', () => {
beforeEach(() => {
fetchMock.resetMocks()
})
const doRequestFN = async() => {
const response = await fetch('http://google.com', {})
console.log(response.headers)
return response.json()
}
test('returns valid values when there are questions answered', async () => {
fetchMock.mockResponseOnce(JSON.stringify({ data: '12345' }))
const response = await doRequestFN()
expect(response).toMatchObject({ data: '12345' })
})
})
// console.log after executing the request.

Is this possible??