Skip to content

Instantly share code, notes, and snippets.

@yamalight
Created October 3, 2016 19:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamalight/6a9f60fe9d5c67a82c3e85a36b6b68c6 to your computer and use it in GitHub Desktop.
Save yamalight/6a9f60fe9d5c67a82c3e85a36b6b68c6 to your computer and use it in GitHub Desktop.
Koa@2 and supertest
import test from 'tape';
import Koa from 'koa';
import supertest from 'supertest';
const app = new Koa();
app.use(ctx => {
ctx.body = 'Hello World';
});
let server;
let request;
test('Start server', t => {
server = app.listen(3000);
request = supertest(server);
t.end();
})
test('Koa test', t => {
request
.get('/')
.expect(200)
.end((err, res) => {
if (err) throw err;
t.equals(res.text, 'Hello World');
t.end();
});
});
test('Shutdown server', t => {
server.close();
t.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment