Asserting the correct response payload

The next test requires that the payload is a JSON object. Since our server is replying with a JSON object, the Content-Type header should also reflect this. Therefore, in our step definition, we should check for both of these criteria. In the spec/cucumber/steps/index.js, update the step definition to the following:

let payload;...Then('the payload of the response should be a JSON object', function () {  const response = result || error;  // Check Content-Type header  const contentType = response.headers['Content-Type'] || response.headers['content-type'];  if (!contentType || !contentType.includes('application/json')) {    throw new Error('Response not of Content-Type application/json');  } // Check it is valid ...

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.