Skip to content

Commit 412eb2e

Browse files
committed
add more tests
1 parent ac746e8 commit 412eb2e

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

packages/fetch/test/request.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ describe('Request', () => {
272272
});
273273
});
274274

275-
it('should read formData after clone with FormData body',async () => {
275+
it('should read formData after clone with web FormData body',async () => {
276276
const ogFormData = new WebFormData();
277277
ogFormData.append('a', 1);
278278
ogFormData.append('b', 2);
@@ -284,11 +284,45 @@ describe('Request', () => {
284284
});
285285
const clonedRequest = request.clone();
286286

287-
return clonedRequest.formData().then(clonedFormData => {
287+
return clonedRequest.formData().then(async clonedFormData => {
288288
expect(clonedFormData.get('a')).to.equal("1");
289289
expect(clonedFormData.get('b')).to.equal("2");
290290
const file = clonedFormData.get('file')
291-
expect(typeof file).to.equal("object");
291+
if (typeof file !== "object") {
292+
throw new Error("File is not an object");
293+
}
294+
expect(file.name).to.equal("file.txt");
295+
expect(file.type).to.equal("application/octet-stream");
296+
expect(file.size).to.equal(7);
297+
expect(await file.text()).to.equal("content");
298+
expect(file.lastModified).to.be.a('number');
299+
});
300+
});
301+
302+
it('should read formData after clone with node FormData body',async () => {
303+
const ogFormData = new FormData();
304+
ogFormData.append('a', '1');
305+
ogFormData.append('b', '2');
306+
ogFormData.append('file', Buffer.from('content'), { filename: "file.txt" });
307+
308+
const request = new Request(base, {
309+
method: 'POST',
310+
body: ogFormData,
311+
});
312+
const clonedRequest = request.clone();
313+
314+
return clonedRequest.formData().then(async clonedFormData => {
315+
expect(clonedFormData.get('a')).to.equal("1");
316+
expect(clonedFormData.get('b')).to.equal("2");
317+
const file = clonedFormData.get('file')
318+
if (typeof file !== "object") {
319+
throw new Error("File is not an object");
320+
}
321+
expect(file.name).to.equal("file.txt");
322+
expect(file.type).to.equal("text/plain");
323+
expect(file.size).to.equal(7);
324+
expect(await file.text()).to.equal("content");
325+
expect(file.lastModified).to.be.a('number');
292326
});
293327
});
294328
});

0 commit comments

Comments
 (0)