add async mock capability.. fixes #26

This commit is contained in:
Lloyd Brookes
2015-12-13 13:02:48 +00:00
parent 7ca0da3d85
commit 5350186614
4 changed files with 47 additions and 2 deletions

View File

@ -335,3 +335,31 @@ test('mock: response function args', function (t) {
.then(server.close.bind(server))
})
})
test('mock: async response function', function (t) {
t.plan(2)
const app = localWebServer({
log: { format: 'none' },
mocks: [
{
route: '/test',
responses: {
response: function (ctx) {
return new Promise((resolve, reject) => {
setTimeout(() => {
ctx.body = 'test'
resolve()
}, 10)
})
}
}
}
]
})
const server = http.createServer(app.callback())
server.listen(8100, () => {
request('http://localhost:8100/test')
.then(checkResponse(t, 200, /test/))
.then(server.close.bind(server))
})
})