The only major problem I ran into with MSW was that the docs advise using their HttpResponse mocking tool, and this resulted in the tests erroring out with this enigmatic message at the point in which HttpResponse was being instantiated:
TypeError: Cannot read properties of undefined (reading '200')
The docs state that we can replace HttpResponse with the built-in Response object, so I did that and the tests proceeded without a hitch.
This general journey mirrored Kent Dodds's journey in Stop mocking fetch.
Changes:
debug
option.docs
script so we can test and experiment locally.undefined
overnull
, to simplify the conditions the consumer must consider.details
structure (breaking change that bumps the major to2.0.0
) so that it's easier to consume.summary.prompt
andchat.rephrasedQuery
in debug response.msw
. ExportscreateServer
as part of the module's interface so consumers can use it in their tests.Notes on testing
I originally tried jest-fetch-mock but ran into some challenges with mocking the streamed response.
I then switched to Mock Service Worker which has guidance on how to mock a streaming API. I took a misstep by trying to use
msw/browser
but then came across https://stackoverflow.com/questions/77399773/cannot-find-module-msw-node-from which pointed me to usemsw/node
because Jest operates in a Node environment.The only major problem I ran into with MSW was that the docs advise using their HttpResponse mocking tool, and this resulted in the tests erroring out with this enigmatic message at the point in which HttpResponse was being instantiated:
The docs state that we can replace
HttpResponse
with the built-inResponse
object, so I did that and the tests proceeded without a hitch.This general journey mirrored Kent Dodds's journey in Stop mocking fetch.