mirror of https://github.com/lukechilds/got.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
726 B
42 lines
726 B
import test from 'ava';
|
|
import got from '../';
|
|
import {createServer} from './helpers/server';
|
|
|
|
let s;
|
|
|
|
test.before('setup', async () => {
|
|
s = await createServer();
|
|
|
|
s.on('/', (req, res) => {
|
|
res.end('ok');
|
|
});
|
|
|
|
s.on('/404', (req, res) => {
|
|
res.statusCode = 404;
|
|
res.end('not found');
|
|
});
|
|
|
|
await s.listen(s.port);
|
|
});
|
|
|
|
test('promise mode', async t => {
|
|
t.is((await got.get(s.url)).body, 'ok');
|
|
|
|
try {
|
|
await got.get(`${s.url}/404`);
|
|
t.fail('Exception was not thrown');
|
|
} catch (err) {
|
|
t.is(err.response.body, 'not found');
|
|
}
|
|
|
|
try {
|
|
await got.get('.com', {retries: 0});
|
|
t.fail('Exception was not thrown');
|
|
} catch (err) {
|
|
t.ok(err);
|
|
}
|
|
});
|
|
|
|
test.after('cleanup', async () => {
|
|
await s.close();
|
|
});
|
|
|