TEST with AVA, SuperTest
git clone [email protected]:0c5752273e7d02cadabc.git
npm i
npm test
node_modules |
TEST with AVA, SuperTest
git clone [email protected]:0c5752273e7d02cadabc.git
npm i
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(); | |
}); | |
}); |