Including test scripts in output code

Hi,

There is a code icon in right side of postman UI that displays corresponding code of request in different languages , but does not contain test script,
Is there any way that this output code includes test scripts also

Hey @orbital-module-cosm2 :wave: Welcome to the Postman Community! :tada:

Thanks for reaching out!
There is no option to include test scripts in code snippets as the scripts depend on the language of your choice.

After pasting the code snippet in a part of your code, you can include some code in that language to achieve what your test scripts does.

The below is my example using NodeJS - Request, and I added line 16 to 21 manually to the code snippet.

var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://postman-echo.com/get',
  'headers': {
  'Content-Type': 'application/json',
  'Cookie': 'Cookie_1=value'
  },
  body: JSON.stringify({
    "myKey": 123
  })
};

request(options, function (error, response) {
  if (error) throw new Error(error);
  const body = JSON.parse(response.body)
  if (body.args.myKey !== 123) {
    console.log('My key value is not correct')
  } else {
    console.log('My key value is correct')
  }
});

Hope this helps! Let me know if you have further questions :slightly_smiling_face:

1 Like