Skip to content

Instantly share code, notes, and snippets.

@zhiyelee
Last active March 2, 2016 20:40
Show Gist options
  • Save zhiyelee/0c5752273e7d02cadabc to your computer and use it in GitHub Desktop.
Save zhiyelee/0c5752273e7d02cadabc to your computer and use it in GitHub Desktop.
AVA_superTest
node_modules

TEST

TEST with AVA, SuperTest

INSTALL

git clone [email protected]:0c5752273e7d02cadabc.git

npm i

RUN

npm test
{
"scripts": {
"test": "ava"
},
"dependencies": {
"ava": "^0.7.0",
"express": "^4.13.3",
"supertest": "^1.1.0"
}
}
'use strict';
let express = require('express');
const app = express();
app.get('/foo', (req, res) => {
res.json('foo from the server');
});
app.get('/foo/:id', (req, res) => {
res.json(req.params.id);
});
module.exports = app;
import test from 'ava';
import app from './server';
import request from 'supertest';
test.beforeEach((t) => {
t.context.request = request(app);
});
test.cb('app.get("/foo")', (t) => {
t.not(5, 3, '5 not equal to 3')
t.context.request
.get('/foo')
.end((err, res) => {
t.is(res.body, 'foo from the server', 'return value should be equal')
t.end();
});
});
test.cb('app.get("/foo/123")', (t) => {
const id = '123';
t.context.request
.get(`/foo/${id}`)
.end((err, res) => {
t.is(res.body, id, 'return value should be equal')
t.end();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment