diff --git a/lib/add-tests.coffee b/lib/add-tests.coffee index bfe56f4..0e737bf 100644 --- a/lib/add-tests.coffee +++ b/lib/add-tests.coffee @@ -85,11 +85,19 @@ addTests = (raml, tests, hooks, parent, callback, testFactory) -> # expect content-type of response body to be identical to request body if contentType && res.body[contentType]?.schema test.response.schema = parseSchema res.body[contentType].schema + try + test.response.example = JSON.parse res.body[contentType]?.example + catch + console.warn "cannot parse JSON example response body for #{test.name}" # otherwise filter in responses section for compatible content-types (vendor tree, i.e. application/vnd.api+json) else contentType = (type for type of res.body when type.match(/^application\/(.*\+)?json/i))?[0] if res.body[contentType]?.schema test.response.schema = parseSchema res.body[contentType].schema + try + test.response.example = JSON.parse res.body[contentType]?.example + catch + console.warn "cannot parse JSON example response body for #{test.name}" callback() , (err) -> @@ -101,4 +109,3 @@ addTests = (raml, tests, hooks, parent, callback, testFactory) -> module.exports = addTests -