-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove non default export to another file
- Loading branch information
Showing
4 changed files
with
51 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default function response (request, headers) { | ||
return { | ||
ok: (request.status/100|0) == 2, // 200-299 | ||
statusText: request.statusText, | ||
status: request.status, | ||
url: request.responseURL, | ||
text: () => Promise.resolve(request.responseText), | ||
json: () => Promise.resolve(JSON.parse(request.responseText)), | ||
blob: () => Promise.resolve(new Blob([request.response])), | ||
clone: () => response(request, headers), | ||
headers: { | ||
keys: () => headers.keys, | ||
entries: () => headers.all, | ||
get: n => headers.raw[n.toLowerCase()], | ||
has: n => n.toLowerCase() in headers.raw | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import response from '../../src/lib/response.mjs'; | ||
|
||
describe('response()', () => { | ||
it('returns text()', () => response({ responseText: 'A passing test.' }) | ||
.text() | ||
.then((text) => expect(text).toBe('A passing test.')) | ||
); | ||
|
||
it('returns blob()', () => response({ response: 'A passing test.' }) | ||
.blob() | ||
.then((text) => expect(text.toString()).toBe(new Blob(['A passing test.']).toString())) | ||
); | ||
|
||
it('returns headers', () => { | ||
const all = [['x-foo', 'bar'], ['x-baz', 'boo']]; | ||
const result = response({}, { all }).headers.entries(); | ||
expect(result).toEqual(all); | ||
}); | ||
|
||
it('returns header keys', () => { | ||
const result = response({}, { keys: ['x-foo'] }).headers.keys(); | ||
expect(result).toEqual(['x-foo']); | ||
}); | ||
|
||
it('returns headers has', () => { | ||
const raw = { 'x-foo': 'bar', 'x-baz': 'boo' }; | ||
const test = response({}, { raw }).headers; | ||
expect(test.has('x-foo')).toBe(true); | ||
}); | ||
}); |