Complete the code to import Supertest and create a request object for the Express app.
const request = require('[1]'); const app = require('./app'); // Use request to test the app
You need to import supertest to create a request object for testing HTTP endpoints.
Complete the code to test that a GET request to '/' returns status 200.
request(app) .get('/') .expect([1], done);
The expected HTTP status code for a successful GET request is 200.
Fix the error in the test to check the response body contains 'Hello World'.
request(app) .get('/') .expect('Content-Type', /json/) .expect([1], done);
The expect method expects an object to match the JSON response body. So use { message: 'Hello World' }.
Fill both blanks to test a POST request sending JSON and expecting status 201.
request(app) .post('/users') .send([1]) .expect([2], done);
We send JSON data { name: 'Alice' } and expect HTTP status 201 which means resource created.
Fill all three blanks to test a PUT request updating a user and checking JSON response.
request(app) .put('/users/123') .send([1]) .expect('Content-Type', /[2]/) .expect([3], done);
The PUT request sends updated data { name: 'Bob' }, expects JSON content type, and a JSON response { success: true }.