Thursday, 8 June 2017

stubbing a method for all instances of a class sinon

try to stub a method getSigningKey of jwksClient however it actually executes the non stub version of the function and returns an error instead of the mockResponse. How to stub it such that it will return the mockResponse instead?

https://github.com/auth0/node-jwks-rsa

const jwksClient = require('jwks-rsa');
sinon.stub(jwksClient(sinon.match.any), 'getSigningKey').callsArgWith(1, null, mockResponse)
const client = auth0authorizer.jwksClient({
     cache: true,
     cacheMaxEntries: 5, // Default value
     cacheMaxAge: ms('10h'), // Default value
     jwksUri: jwksUri
});
client.getSigningKey('abc',(err,key) => {
  // doesn't stub returns error
})



via Stanley

No comments:

Post a Comment