我试图从路由处理程序模拟函数......
这是我的路线:
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({});
任何人都知道如何使这个工作?