Created
October 3, 2016 19:29
-
-
Save yamalight/6a9f60fe9d5c67a82c3e85a36b6b68c6 to your computer and use it in GitHub Desktop.
Koa@2 and supertest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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