Sindre Sorhus 9 years ago
parent
commit
b09afd0ce5
  1. 2
      package.json
  2. 10
      test/error.js
  3. 2
      test/gzip.js
  4. 2
      test/helpers.js
  5. 2
      test/http.js
  6. 2
      test/https.js
  7. 6
      test/json.js
  8. 2
      test/redirects.js
  9. 8
      test/retry.js
  10. 4
      test/stream.js

2
package.json

@ -59,7 +59,7 @@
"url-parse-lax": "^1.0.0"
},
"devDependencies": {
"ava": "^0.13.0",
"ava": "^0.14.0",
"coveralls": "^2.11.4",
"get-port": "^2.0.0",
"into-stream": "^2.0.0",

10
test/error.js

@ -20,10 +20,10 @@ test('properties', async t => {
await got(s.url);
t.fail('Exception was not thrown');
} catch (err) {
t.ok(err);
t.ok(err.response);
t.ok(!err.propertyIsEnumerable('response'));
t.ok(!err.hasOwnProperty('code'));
t.truthy(err);
t.truthy(err.response);
t.truthy(!err.propertyIsEnumerable('response'));
t.truthy(!err.hasOwnProperty('code'));
t.is(err.message, 'Response code 404 (Not Found)');
t.is(err.host, `${s.host}:${s.port}`);
t.is(err.method, 'GET');
@ -35,7 +35,7 @@ test('dns message', async t => {
await got('.com', {retries: 0});
t.fail('Exception was not thrown');
} catch (err) {
t.ok(err);
t.truthy(err);
t.regex(err.message, /getaddrinfo ENOTFOUND/);
t.is(err.host, '.com');
t.is(err.method, 'GET');

2
test/gzip.js

@ -49,7 +49,7 @@ test('handles gzip error', async t => {
});
test('preserve headers property', async t => {
t.ok((await got(s.url)).headers);
t.truthy((await got(s.url)).headers);
});
test('do not break HEAD responses', async t => {

2
test/helpers.js

@ -33,7 +33,7 @@ test('promise mode', async t => {
await got.get('.com', {retries: 0});
t.fail('Exception was not thrown');
} catch (err) {
t.ok(err);
t.truthy(err);
}
});

2
test/http.js

@ -53,7 +53,7 @@ test('error with code', async t => {
test('buffer on encoding === null', async t => {
const data = (await got(s.url, {encoding: null})).body;
t.ok(Buffer.isBuffer(data));
t.truthy(Buffer.isBuffer(data));
});
test('timeout option', async t => {

2
test/https.js

@ -39,7 +39,7 @@ test.before('setup', async () => {
});
test('make request to https server without ca', async t => {
t.ok((await got(s.url, {rejectUnauthorized: false})).body);
t.truthy((await got(s.url, {rejectUnauthorized: false})).body);
});
test('make request to https server with ca', async t => {

6
test/json.js

@ -34,7 +34,7 @@ test.before('setup', async () => {
});
test('parses response', async t => {
t.same((await got(s.url, {json: true})).body, {data: 'dog'});
t.deepEqual((await got(s.url, {json: true})).body, {data: 'dog'});
});
test('not parses responses without a body', async t => {
@ -48,7 +48,7 @@ test('wraps parsing errors', async t => {
t.fail('Exception was not thrown');
} catch (err) {
t.regex(err.message, /Unexpected token/);
t.ok(err.message.indexOf(err.hostname) !== -1, err.message);
t.truthy(err.message.indexOf(err.hostname) !== -1, err.message);
t.is(err.path, '/invalid');
}
});
@ -58,7 +58,7 @@ test('parses non-200 responses', async t => {
await got(`${s.url}/non200`, {json: true});
t.fail('Exception was not thrown');
} catch (err) {
t.same(err.response.body, {data: 'dog'});
t.deepEqual(err.response.body, {data: 'dog'});
}
});

2
test/redirects.js

@ -123,7 +123,7 @@ test('redirect only GET and HEAD requests', async t => {
});
test('redirects from http to https works', async t => {
t.ok((await got(`${http.url}/httpToHttps`, {rejectUnauthorized: false})).body);
t.truthy((await got(`${http.url}/httpToHttps`, {rejectUnauthorized: false})).body);
});
test('redirects works with lowercase method', async t => {

8
test/retry.js

@ -40,7 +40,7 @@ test('can be disabled with option', async t => {
await got(`${s.url}/try-me`, {timeout: 500, retries: 0});
t.fail();
} catch (err) {
t.ok(err);
t.truthy(err);
t.is(trys, 1);
}
});
@ -54,18 +54,18 @@ test('falsy value prevents retries', async t => {
try {
await got(`${s.url}/long`, {timeout: 100, retries: () => 0});
} catch (err) {
t.ok(err);
t.truthy(err);
}
});
test('falsy value prevents retries #2', async t => {
try {
await got(`${s.url}/long`, {timeout: 100, retries: (iter, err) => {
t.ok(err);
t.truthy(err);
return false;
}});
} catch (err) {
t.ok(err);
t.truthy(err);
}
});

4
test/stream.js

@ -66,7 +66,7 @@ test.cb('throws on write to stream with body specified', t => {
test.cb('have request event', t => {
got.stream(s.url)
.on('request', req => {
t.ok(req);
t.truthy(req);
t.end();
});
});
@ -95,7 +95,7 @@ test.cb('have error event', t => {
.on('error', (err, data, res) => {
t.is(err.message, 'Response code 404 (Not Found)');
t.is(null, data);
t.ok(res);
t.truthy(res);
t.end();
});
});

Loading…
Cancel
Save