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; ...