How to make a node script of Newman fail when a test fails How to make a node script of Newman fail when a test fails jenkins jenkins

How to make a node script of Newman fail when a test fails


Add assertion "Chai" library to your tests and use its methods to assert the result of your testsread more:https://www.chaijs.com/https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox_api_reference

const chai = require('chai') expect = chai.expect;

and put an assertion depending on what you want to assert (statusCode, reposneBody etc)For Instance: assert that you expect your response body will have an array with 3 objects inside

.on('request', function (err, args) {                if (!err) {                    // here, args.response represents the entire response object                    var rawBody = args.response.stream, // this is a buffer                    body = rawBody.toString(); // stringified JSON                    results.push(JSON.parse(body)); // this is just to aggregate all responses into one object                    expect(body.array.length === 3).to.equal(true)// **EXAMPLE**                }            })

or

pm.expect(res).to.have.property('code', 200);pm.expect(res).to.have.property('status', 'OK');

both check status code of the response on your request.

Read: https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox_api_reference