-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathresponse.js
More file actions
32 lines (26 loc) · 948 Bytes
/
response.js
File metadata and controls
32 lines (26 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import response from '../../src/lib/response.mjs';
describe('response()', () => {
const raw = { 'x-foo': 'foo', 'x-bar': 'bar' };
const keys = Object.keys(raw);
const all = Object.entries(raw);
const resp = response({}, all, keys, raw);
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', () => {
expect(resp.headers.entries()).toEqual(all);
});
it('returns header keys', () => {
expect(resp.headers.keys()).toEqual(['x-foo', 'x-bar']);
});
it('returns headers has', () => {
expect(resp.headers.has('x-foo')).toBe(true);
expect(resp.headers.has('x-bar')).toBe(true);
expect(resp.headers.has('x-baz')).toBe(false);
});
});