Code Monkey home page Code Monkey logo

Comments (6)

vinz243 avatar vinz243 commented on July 18, 2024 21

I had to return app.listen()instead of app. thanks anyway

from node-supertest-koa-agent.

imaustink avatar imaustink commented on July 18, 2024 7

You can simply do supertest(app.callback()) and it works as expected. No need to wrap it in a server.

from node-supertest-koa-agent.

whyhankee avatar whyhankee commented on July 18, 2024 6

As said above it's bad practice to start an application-server on a port when running tests and it's not needed. However, yes, supertest would like a server. So, I fixed it by using:

import * as http from 'http';
import * as supertest from 'supertest';
import * as test from 'tape';

import app from '../app';
const apptest = supertest(http.createServer(app.callback()));

test('GET /healthcheck', (t) => {
    apptest.get('/healthcheck')
    .expect(200)
    .expect(res => {
      t.equal(res.text, 'Ok');
    })
    .end(t.end.bind(t));
});

from node-supertest-koa-agent.

iamgollum avatar iamgollum commented on July 18, 2024 5

Its bad practice to depend on an express server running in a test environment.

I was able to get this working by not using export default app and instead use module.exports = app. Try that!

Also you don't need to use the supertest-as-promised now as supertest now supports native promises. When I ran into this issue I was using a different promise supertest library but got the same error.

from node-supertest-koa-agent.

wilmoore avatar wilmoore commented on July 18, 2024

I haven't tried this with supertest-as-promised; however, I wonder if you might need to call supertest.agent?

from node-supertest-koa-agent.

wilmoore avatar wilmoore commented on July 18, 2024

👍

from node-supertest-koa-agent.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.