Reputation: 633
How do I make it work?
Goal: call a variable inside test script
Test script:
pm.test("shipment registration not allowed", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.results[0].errors.title).to.eql(pm.errors.get("shipmentRegistrationNotAllowed"));
});
The error:
Error: TypeError: Cannot read property 'get' of undefined
Upvotes: 5
Views: 16545
Reputation: 25881
I'm not sure where you have found pm.errors.get
as a function that you can use but I don't believe it is something that is within Postman.
All the sandbox functions can be found here https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox_api_reference
If you are just looking to assert that jsonData.results[0].errors.title
equals a string value, you could just do this:
pm.test("shipment registration not allowed", () => {
var jsonData = pm.response.json()
pm.expect(jsonData.results[0].errors.title).to.eql(pm.globals.get("my_error_value"))
})
If you set a global
variable you can reference in the test like this:
Upvotes: 4