Search code examples
node.jstypescriptexpresssinonstub

Using Sinon SinonStubbedInstance with Typescript


I'm using sinon to stub an instance of express-Request.
It looks something like this:

let req = sinon.createStubInstance(Request);

My method accepts req: Request but my IDE complains about me using SinonStubbedInstance<Request> rather than Request.
I've tried using req as Request but I still get a warning about 'may be a mistake' and that I should first cast to unknown and only then to Request.

I actually don't need anything from this parameter so I really just want to stub it quickly and easily.


Solution

  • When using it in the call to your method, just cast it:

    myMethod(req as any);