Comments (6)
I had to return app.listen()
instead of app. thanks anyway
from node-supertest-koa-agent.
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.
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.
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.
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.
👍
from node-supertest-koa-agent.
Related Issues (5)
- Unable to use this in simple tests HOT 1
- Publish latest version HOT 1
- Publish 0.3.1 version HOT 4
- deprecated warning HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-supertest-koa-agent.