Closed jestrickler closed 2 years ago
I figured something out, but i'm overriding the mock rather than using it...
const mockRead = jest.fn()
mockRead.mockReturnValueOnce({ done: false, value: 'this is my blob text' })
mockRead.mockReturnValueOnce({ done: true })
jest.spyOn(global, 'fetch').mockImplementation(() =>
Promise.resolve().then(() => ({
body: {
getReader: () => ({ read: mockRead })
}
}))
)
This wouldn't work if I tried to put the same body in fetch.mockResponseOnce
I'd like to write a test related to the following code:
Is this possible? How would I go about mocking the response to get a mockReader? Thanks in advance!