1
我試圖從路由處理模擬功能...我如何存根Hapi處理程序?
這裏是我的路線:
server.route({
method: 'GET',
path: '/api/color/{format}',
handler: this.pingLogic.getPing,
config: {
description: 'This is ping route',
tags: ['api', 'v1', 'ping route'],
validate: {
params: pingValidator
}
}
})
getPing功能如下:
getPing(req: HapiRequest, reply: Hapi.ReplyNoContinue): any {
req.seneca
.act(
{
role: 'color',
format: req.params.format,
color: 'red'
},
(err: any, out: any): any => {
return reply(err || out)
}
)
}
這裏是我的測試:
L.test('returns the hello message as text.', (done) => {
const ping = new PingLogic;
sinon.stub(ping, 'getPing').returns({});
server.inject('/api/color/hex', (response: any) => {
expect(response.payload).to.equal({color: 'green'});
done();
});
});
它不工作它不承認這部分:sinon.stub(ping, 'getPing').returns({});
任何人都知道如何使這項工作?