How to stub a private method of a class written in typescript using sinon
The problem is that the definition for sinon
uses the following definition for the stub
function :
interface SinonStubStatic { <T>(obj: T, method: keyof T): SinonStub; }
This means that the second parameter must be the name of a member (a public one) of the T
type. This is probably a good restriction generally, but in this case it is a bit too restrictive.
You can get around it by casting to any
:
sinon.stub(A.prototype, <any>"method2");