J'essaie de la fonction simulation du gestionnaire d'itinéraire ...Comment puis-je remplacer le gestionnaire Hapi?
Voici mon itinéraire:
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
}
}
})
fonction getPing ressemble à ceci:
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)
}
)
}
Voici mon test:
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();
});
});
Cela ne fonctionne pas, il ne reconnaît pas cette partie: sinon.stub(ping, 'getPing').returns({});
Quelqu'un sait comment faire ce travail?