|
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 }));
}
}
), |
Answered by
nemanjam
Jun 12, 2022
Replies: 3 comments
|
No help here after 2 months? |
0 replies
|
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; |
0 replies
Answer selected by
nemanjam
|
Patching Reader Polyfill Worker Thread for Reader Polyfill |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I parsed it like this, thank you for help.