Skip to content

Instantly share code, notes, and snippets.

@JamesMessinger
Created July 27, 2017 19:23
Show Gist options
  • Save JamesMessinger/bef06d26de2145bbf0a5de2addd77eaf to your computer and use it in GitHub Desktop.
Save JamesMessinger/bef06d26de2145bbf0a5de2addd77eaf to your computer and use it in GitHub Desktop.
Saving JavaScript code to a variable in Postman
// Save common tests in a global variable
postman.setGlobalVariable("commonTests", () => {
// The Content-Type must be JSON
tests["Content-Type header is set"] = postman.getResponseHeader("Content-Type") === "application/json";
// The response time must be less than 500 milliseconds
tests["Response time is acceptable"] = responseTime < 500;
// The response body must include an "id" property
var data = JSON.parse(responseBody);
tests["Response has an ID"] = data.id !== undefined;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment