Last active
June 27, 2018 10:02
-
-
Save jameshd/891f962eb98f753a85cb0974f0a85b7b to your computer and use it in GitHub Desktop.
Loosely detecting JSON responses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// console.log(pm.response.headers.has('application/json')); doesn't work, too strict. | |
const isJsonResponse = (pm.response.headers.filter((header) => header.value.indexOf('application/json') !== -1).length > 0); | |
if (isJsonResponse) { | |
pm.test("it should match schema", () => { | |
const schema = { | |
"$schema": "http://json-schema.org/draft-06/schema#", | |
"$ref": "#/definitions/Welcome", | |
"definitions": { | |
// ... schema generated at https://app.quicktype.io | |
} | |
} | |
pm.expect(tv4.validate(pm.response.json(), schema)).to.be.true; | |
}); | |
} |
ohh the deconstructing the object... nice...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
or even