Testing WebApp.connecthandlers


Has anyone done this? If you have could you point me to an example etc.

I am going to give supertest a shot but thought I’d also ask the community to find out if anyone has done this.



Are you talking about testing your handler? Or the implementation of connectHandlers in general?

We tested the former by exporting the function we pass to the handler and then importing it into a test case and passing in a stubbed request object (with dummy data), response object and next function to check that expected calls were made.

The actual functionality of our handlers was easier to test as we don’t need to handle streaming, so our handler just waits for the body of the request to be complete, then passes that as a string to our actual function.


Yes, testing my handler.

We are streamimg, actually proxying requests to another service with different credentials.

Ideally we’d test outside in, emulating the full request, stubbing out the remote service with local fake endpoint.

But a good fallback is what you’ve mentioned, put the proxy logic in it’s own function to be unit tested in isolation.

As I mentioned, we’re going to see if we can emulate the full request and if not fall back to isolated function.


@znewsham / went with suggestion worked out great. Thanks