Testing the web server
So far, we have learned how to test different parts of the application. We started with the business logic, which tests how it integrated with the modules that interacted with persistency (the repository), but the web layer still has no tests.
It's true that those tests are very important, but we can agree that if the web layer fails, the user will not have access to any of that logic.
That's what we'll do in this section. We'll spin up our web server, mock its dependencies, and make a few requests to it to ensure the web unit is working.
Let's start by creating the web module's unit test by following these steps:
- Go to
src/web
and create a file namedweb.test.ts
. - Now, in order to test the web server, we need to go back to the
createServer
function insrc/web/index.ts
and export theApplication
object it creates insrc/web/index.ts
:const app = new Application(); … return { app };
- We also want to be...