Is it possible to unit test a middleware in nestjs without loading up the whole app? Can I do something like this:
const middleware = new XxxMiddleware();
someTestingFunction.mock(middleware, testingReq).expect(resultReq).eq(...something)
Is it possible to unit test a middleware in nestjs without loading up the whole app? Can I do something like this:
const middleware = new XxxMiddleware();
someTestingFunction.mock(middleware, testingReq).expect(resultReq).eq(...something)
Nothing forbid that way to test a middleware, you just need to mock the args of the resolve method by mocking the request, response and pass a callback as next parameter
Here an example, but there is many of them. https://codeburst.io/unit-testing-in-express-with-promise-based-middleware-and-controllers-7d3d59ae61f8?gi=666ca5b33daa