-
I have form that sends two images with additional fields as const methods = useForm<SettingsFormData>({
resolver: zodResolver(userUpdateSchema),
defaultValues: {
username: '',
name: '',
bio: '',
avatar: undefined,
header: undefined,
password: '',
confirmPassword: '',
},
}); I have patch handler that receives this data, but I want to return user as json data and to assert it in the test. On real server this handles multer but how should I do this with msw? Do you know any useful similar example? rest.patch<DefaultRequestBody, PathParams, ClientUser>(
`${Routes.API.USERS}:id`,
(req, res, ctx) => {
const userId = req.params.id;
if (fakeUser.id !== userId) throw new Error('Invalid fake user.id.');
if (userId) {
const user = req.body; // parse from FormData here???
return res(ctx.status(200), ctx.json({ ...fakeUser, ...user }));
}
}
), |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
No help here after 2 months? |
Beta Was this translation helpful? Give feedback.
-
I parsed it like this, thank you for help. // parse ClientUser from FormData
const myFormData = req.body as FormData;
const user = Object.fromEntries(myFormData.entries()) as unknown as ClientUser; |
Beta Was this translation helpful? Give feedback.
-
Patching
Reader Polyfill
Worker Thread for Reader Polyfill
|
Beta Was this translation helpful? Give feedback.
I parsed it like this, thank you for help.