Codemod verified
Regularly tested and maintained by our engineers and codemod expert community.
Msw
migration
byCodemod
Msw/2/Ctx Fetch
Last update
Jul 24, 2024
ctx.fetch(req)
is now meant to be called as fetch(bypass(req))
where bypass
is a new function available in the msw
library. Changes applied by this codemod:
ctx.fetch(req)
is replaced withfetch(bypass(req))
.
NOTE: The bypass
call is meant to wrap the new request
object available on the callback argument. This object is not being destructured in this codemod, so you will have to do it manually or run a callback-signature
codemod that will do that and replace the reference for you.
Before
import { rest } from 'msw';const handlers: RestHandler[] = [rest.get('/user', async (req, res, ctx) => {const originalRequest = await ctx.fetch(req);return res(ctx.json({ firstName: 'John' }));}),];
After
import { rest } from 'msw';const handlers: RestHandler[] = [rest.get('/user', async (req, res, ctx) => {const originalRequest = await fetch(bypass(req));return res(ctx.json({ firstName: 'John' }));}),];
Build custom codemods
Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community