Skip to content

Instantly share code, notes, and snippets.

@Tinh96nb
Forked from yamalight/test.js
Created January 29, 2018 10:16
Show Gist options
  • Save Tinh96nb/426b2527ee21df06d4b444d75f7d8647 to your computer and use it in GitHub Desktop.
Save Tinh96nb/426b2527ee21df06d4b444d75f7d8647 to your computer and use it in GitHub Desktop.
Koa and supertest example
const test = require('tape');
const koa = require('koa');
const supertest = require('supertest');
const app = koa();
app.use(function *(){
this.body = 'Hello World';
});
let server;
let request;
test('Start server', t => {
server = app.listen();
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