Files
test-repo/tests/flow/fetch/request.js
T
Christopher Chedeau 3375cfe605 Move tests around (#454)
* new_tests

* move_all_clobbered_tests

* remove all the tests that no longer exist

* re-run flow tests

* Move all the flow tests to tests/flow and prettier to tests/

* Move prettier tests to their own folders

* Add jsfmt files

* run prettier snapshot tests
2017-01-24 14:35:37 -08:00

52 lines
1.4 KiB
JavaScript

/* @flow */
const a: Request = new Request(); // incorrect
const b: Request = new Request('http://example.org'); // correct
const c: Request = new Request(b); // correct
const d: Request = new Request(c.clone()); // correct (doesn't make much sense though)
const e: Request = new Request(b, c); // incorrect
const f: Request = new Request({}) // incorrect
const g: Request = new Request('http://example.org', {}) // correct
const h: Request = new Request('http://example.org', {
method: 'GET',
headers: {
'Content-Type': 'image/jpeg'
},
mode: 'cors',
cache: 'default'
}) // correct
const i: Request = new Request('http://example.org', {
method: 'POST',
headers: {
'Content-Type': 'image/jpeg'
},
body: new URLSearchParams("key=value"),
mode: 'cors',
cache: 'default'
}) // correct
const j: Request = new Request('http://example.org', {
method: 'GET',
headers: 'Content-Type: image/jpeg',
mode: 'cors',
cache: 'default'
}) // incorrect - headers is string
const k: Request = new Request('http://example.org', {
method: 'CONNECT',
headers: {
'Content-Type': 'image/jpeg'
},
mode: 'cors',
cache: 'default'
}) // incorrect - CONNECT is forbidden
var l: boolean = h.bodyUsed;
h.text().then((t: string) => t); // correct
h.text().then((t: Buffer) => t); // incorrect
h.arrayBuffer().then((ab: ArrayBuffer) => ab); // correct
h.arrayBuffer().then((ab: Buffer) => ab); // incorrect