Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Mar 16, 2020
1 parent 258a0aa commit b5680f3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/http.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from 'ava';
import getStream = require('get-stream');
import got, {HTTPError, UnsupportedProtocolError} from '../source';
import withServer from './helpers/with-server';

Expand Down Expand Up @@ -82,6 +83,28 @@ test('custom `options.encoding`', withServer, async (t, server, got) => {
t.is(data, Buffer.from(string).toString('base64'));
});

test('`options.encoding` doesn\'t affect streams', withServer, async (t, server, got) => {
const string = 'ok';

server.get('/', (_request, response) => {
response.end(string);
});

const data = await getStream(got.stream({encoding: 'base64'}));
t.is(data, string);
});

test('`got.stream(...).setEncoding(...)` works', withServer, async (t, server, got) => {
const string = 'ok';

server.get('/', (_request, response) => {
response.end(string);
});

const data = await getStream(got.stream('').setEncoding('base64'));
t.is(data, Buffer.from(string).toString('base64'));
});

test('`searchParams` option', withServer, async (t, server, got) => {
server.get('/', (request, response) => {
t.is(request.query.recent, 'true');
Expand Down

0 comments on commit b5680f3

Please sign in to comment.