Supertest: (using with Hapi) app.address is not a function

Created on 6 Aug 2017  路  3Comments  路  Source: visionmedia/supertest

I'm trying to setup supertest with my Hapi.js server. I'm not sure if this is the correct way. Please advise me on what is..

in my server.js,

const const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ 
    // host: '0.0.0.0', 
    port: process.env.PORT || 8080,
    routes: { cors: true }
});
server.route([
{
    method: 'GET',
    path:'/', 
    handler: (request, reply) => {

        return reply('hello world');
    },
    config: { auth: false }
}
]);
module.exports = server;

then in my server.test.js

const request = require('supertest');
const server = require('./server');
it('gets a response', () => {
    request(server)
        .get('/')
        .set('Accept', 'application/json')
        .expect('Content-Type', /json/)
        .expect(200, done);
});

am I exporting the wrong thing?

too-old

Most helpful comment

Use server.listener

All 3 comments

Use server.listener

same issue with fastify

Regarding fastify:

fixed with request(app.server)

you might also want to use a specific port / depending on how complex your tests are...

app.listen('3001');

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rkmax picture rkmax  路  5Comments

peterjuras picture peterjuras  路  3Comments

NBNARADHYA picture NBNARADHYA  路  4Comments

jon301 picture jon301  路  5Comments

mickaeltr picture mickaeltr  路  3Comments