Asserting the correct response payload content

Now, on to our last test. We need our error object payload to contain a message property that reads "Payload should not be empty". So first, let's implement our test:

Then('contains a message property which says "Payload should not be empty"', function () {  if (payload.message !== 'Payload should not be empty') {    throw new Error();  }});

Next, run the tests again and they should fail. Then, to make it pass, we need to pass a different object into the res.end method. Your if block should now look like this:

if (req.method === 'POST' && req.url === '/users') {  res.writeHead(400, { 'Content-Type': 'application/json' });  res.end(JSON.stringify({    message: 'Payload should not be empty',  })); return; ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.