@whatwg-node/fetch
Advanced tools
Comparing version 0.4.5-alpha-20220925232816-030a991 to 0.4.5-alpha-20220925233002-c4d7b92
# @whatwg-node/fetch | ||
## 0.4.5-alpha-20220925232816-030a991 | ||
## 0.4.5-alpha-20220925233002-c4d7b92 | ||
@@ -5,0 +5,0 @@ ### Patch Changes |
{ | ||
"name": "@whatwg-node/fetch", | ||
"version": "0.4.5-alpha-20220925232816-030a991", | ||
"version": "0.4.5-alpha-20220925233002-c4d7b92", | ||
"description": "Cross Platform Smart Fetch Ponyfill", | ||
@@ -5,0 +5,0 @@ "author": "Arda TANRIKULU <ardatanrikulu@gmail.com>", |
import { createFetch } from '@whatwg-node/fetch'; | ||
describe('getFormDataMethod', () => { | ||
['fieldsFirst:true', 'fieldsFirst:false'].forEach((fieldsFirstFlag) => { | ||
const fetchAPI = createFetch({ | ||
formDataLimits: { | ||
fieldsFirst: fieldsFirstFlag === 'fieldsFirst:true', | ||
} | ||
['fieldsFirst:true', 'fieldsFirst:false'].forEach(fieldsFirstFlag => { | ||
const fetchAPI = createFetch({ | ||
formDataLimits: { | ||
fieldsFirst: fieldsFirstFlag === 'fieldsFirst:true', | ||
}, | ||
}); | ||
describe(fieldsFirstFlag, () => { | ||
it('should parse fields correctly', async () => { | ||
const formData = new fetchAPI.FormData(); | ||
formData.append('greetings', 'Hello world!'); | ||
formData.append('bye', 'Goodbye world!'); | ||
const request = new fetchAPI.Request('http://localhost:8080', { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
describe(fieldsFirstFlag, () => { | ||
it('should parse fields correctly', async () => { | ||
const formData = new fetchAPI.FormData(); | ||
formData.append('greetings', 'Hello world!'); | ||
formData.append('bye', 'Goodbye world!'); | ||
const request = new fetchAPI.Request('http://localhost:8080', { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
const formdata = await request.formData(); | ||
expect(formdata.get('greetings')).toBe('Hello world!'); | ||
expect(formdata.get('bye')).toBe('Goodbye world!'); | ||
}); | ||
it('should parse and receive text files correctly', async () => { | ||
const formData = new fetchAPI.FormData(); | ||
const greetingsFile = new fetchAPI.File(['Hello world!'], 'greetings.txt', { type: 'text/plain' }); | ||
const byeFile = new fetchAPI.File(['Goodbye world!'], 'bye.txt', { type: 'text/plain' }); | ||
formData.append('greetings', greetingsFile); | ||
formData.append('bye', byeFile); | ||
const request = new fetchAPI.Request('http://localhost:8080', { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
const formdata = await request.formData(); | ||
const receivedGreetingsFile = formdata.get('greetings') as File; | ||
const receivedGreetingsText = await receivedGreetingsFile.text(); | ||
expect(receivedGreetingsText).toBe('Hello world!'); | ||
const receivedByeFile = formdata.get('bye') as File; | ||
const receivedByeText = await receivedByeFile.text(); | ||
expect(receivedByeText).toBe('Goodbye world!'); | ||
}); | ||
}) | ||
}) | ||
}) | ||
const formdata = await request.formData(); | ||
expect(formdata.get('greetings')).toBe('Hello world!'); | ||
expect(formdata.get('bye')).toBe('Goodbye world!'); | ||
}); | ||
it('should parse and receive text files correctly', async () => { | ||
const formData = new fetchAPI.FormData(); | ||
const greetingsFile = new fetchAPI.File(['Hello world!'], 'greetings.txt', { type: 'text/plain' }); | ||
const byeFile = new fetchAPI.File(['Goodbye world!'], 'bye.txt', { type: 'text/plain' }); | ||
formData.append('greetings', greetingsFile); | ||
formData.append('bye', byeFile); | ||
const request = new fetchAPI.Request('http://localhost:8080', { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
const formdata = await request.formData(); | ||
const receivedGreetingsFile = formdata.get('greetings') as File; | ||
const receivedGreetingsText = await receivedGreetingsFile.text(); | ||
expect(receivedGreetingsText).toBe('Hello world!'); | ||
const receivedByeFile = formdata.get('bye') as File; | ||
const receivedByeText = await receivedByeFile.text(); | ||
expect(receivedByeText).toBe('Goodbye world!'); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
620
26932