Skip to content

Commit

Permalink
Merge pull request hapijs#234 from dominykas/test-empty-response
Browse files Browse the repository at this point in the history
Lock in empty response behavior
  • Loading branch information
hueniverse authored Nov 11, 2018
2 parents 1345862 + b07f1c7 commit add428d
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,60 @@ describe('Client', () => {
client.disconnect();
await server.stop();
});

describe('empty response handling', () => {

[
{
testName: 'handles empty string, no content-type',
handler: () => '',
expectedPayload: ''
},
{
testName: 'handles null, no content-type',
handler: () => null,
expectedPayload: null
},
{
testName: 'handles null, application/json',
handler: (request, h) => h.response(null).type('application/json'),
expectedPayload: null
},
{
testName: 'handles empty string, text/plain',
handler: (request, h) => h.response('').type('text/plain'),
expectedPayload: ''
},
{
testName: 'handles null, text/plain',
handler: (request, h) => h.response(null).type('text/plain'),
expectedPayload: null
}
].forEach(({ testName, handler, expectedPayload }) => {

it(testName, async () => {

const server = Hapi.server();
await server.register({ plugin: Nes, options: { auth: false, headers: '*' } });

server.route({
method: 'GET',
path: '/',
handler
});

await server.start();
const client = new Nes.Client('http://localhost:' + server.info.port);
await client.connect();

const { payload } = await client.request({ path: '/' });
expect(payload).to.equal(expectedPayload);

client.disconnect();
await server.stop();
});
});
});
});

describe('message()', () => {
Expand Down

0 comments on commit add428d

Please sign in to comment.