I have a test I'm trying to write for a request that uses FormData to submit a multipart form. I'm using Nock to try to mock the request
const submit_claim_request = nock(gatewayClient.defaults.baseURL)
.post('/api/v2/claims', (body) => {
return (
JSON.stringify(body) === //<-------- this does not work
{
default_employee_wallet_id: '0000000046',
amount: 1,
category: 'Parking',
reimbursement_vendor: 'Test vendor',
transaction_date: '2021-10-03T00:00:00.000Z',
note: 'test description',
is_multi_month: false,
'file[]': file,
}
);
})
.reply(200, {
data: {
reimbursement: {
amount: '1',
category: 'Parking',
},
},
});
However, I can't figure out how to convert my FormData from my Axios request to a JS object.
This is what my body
looks like:
----------------------------792417295264678490134208
Content-Disposition: form-data; name="default_employee_wallet_id"
5cc7f9432e041785dea91a7a
----------------------------792417295264678490134208
Content-Disposition: form-data; name="amount"
1
----------------------------792417295264678490134208
Content-Disposition: form-data; name="reimbursement_vendor"
Test vendor
----------------------------792417295264678490134208
Content-Disposition: form-data; name="category"
gym_and_fitness
----------------------------792417295264678490134208
Content-Disposition: form-data; name="transaction_date"
2021-10-03T00:00:00.000Z
----------------------------792417295264678490134208
Content-Disposition: form-data; name="is_multi_month"
false
----------------------------792417295264678490134208
Content-Disposition: form-data; name="note"
test description
----------------------------792417295264678490134208
Content-Disposition: form-data; name="file[]"; filename="chucknorris1.png"
Content-Type: image/png
(⌐□_□)
----------------------------792417295264678490134208--