Complete the code to import the testing library for integration tests.
import [1] from 'supertest';
The supertest library is commonly used for integration testing HTTP servers in Node.js. We import it as request to make HTTP calls in tests.
Complete the code to start the server before running integration tests.
beforeAll(async () => {
server = app.[1](3000);
});The listen method starts the server on a given port so it can accept requests during tests.
Fix the error in the test by completing the assertion method.
expect(response.status).to[1](200);
In Jest, the correct matcher to check equality is toBe. Other options are invalid or cause errors.
Fill both blanks to create a test that sends a POST request with JSON data.
await request(app) .post('/api/data') .set('Content-Type', '[1]') .send({ key: 'value' }) .expect([2]);
The header Content-Type should be set to application/json when sending JSON data. The expected status code for a successful POST is usually 200.
Fill all three blanks to write a test that checks the response body for a specific property.
test('response has user id', async () => { const response = await request(app).get('/user/123'); expect(response.body).toHaveProperty('[1]'); expect(typeof response.body.id).to[2]('string'); expect(response.body.id).not.to[3](''); });
The property to check is id. The Jest matcher to check type equality is toBe. To check that the id is not an empty string, use equal with negation.