Supertest for HTTP assertions
📖 Scenario: You are building a simple web server using Express. You want to check that your server responds correctly to HTTP requests. This is like testing if a vending machine gives you the right snack when you press a button.
🎯 Goal: Build a small Express server and write tests using Supertest to check the server's responses. You will create the server, set up Supertest, write a test for the home page, and finally add a test for a JSON response.
📋 What You'll Learn
Create an Express app with a GET route at '/' that returns 'Hello World!'
Set up Supertest to test the Express app
Write a test that checks the '/' route returns status 200 and text 'Hello World!'
Add a GET route at '/data' that returns JSON { message: 'Hello JSON' }
Write a test that checks the '/data' route returns status 200 and the correct JSON
💡 Why This Matters
🌍 Real World
Testing web servers ensures they respond correctly before users see them. This prevents bugs and improves reliability.
💼 Career
Backend developers often write tests with Supertest to verify APIs work as expected, which is a key skill in web development jobs.
Progress0 / 4 steps