mirror of
https://github.com/koajs/examples.git
synced 2026-01-18 14:38:19 +00:00
* Remove duplicate supertest dependency * Fix mocha version * Add an after statement to close koa app instance after running tests
42 lines
973 B
JavaScript
42 lines
973 B
JavaScript
require('should');
|
|
const app = require('./app');
|
|
const server = app.listen();
|
|
const request = require('supertest').agent(server);
|
|
|
|
describe('Flash Messages', function() {
|
|
after(function() {
|
|
server.close();
|
|
});
|
|
|
|
it('GET should return an empty array', function(done) {
|
|
request
|
|
.get('/messages')
|
|
.expect(200)
|
|
.expect('content-type', 'application/json; charset=utf-8')
|
|
.expect('[]', done);
|
|
});
|
|
|
|
it('POST should return 204', function(done) {
|
|
request
|
|
.post('/messages')
|
|
.send('hello')
|
|
.expect(204, done);
|
|
});
|
|
|
|
it('GET should return the message', function(done) {
|
|
request
|
|
.get('/messages')
|
|
.expect(200)
|
|
.expect('content-type', 'application/json; charset=utf-8')
|
|
.expect('["hello"]', done);
|
|
});
|
|
|
|
it('GET should return no more messages', function(done) {
|
|
request
|
|
.get('/messages')
|
|
.expect(200)
|
|
.expect('content-type', 'application/json; charset=utf-8')
|
|
.expect('[]', done);
|
|
});
|
|
});
|