I’m new to Postman and looking for some help please.
I have stored a variable called ‘value’ from a previous request.
I have made a further request to a different API which also returns ‘value’.
I want to assert that the value returned in my latest call is the same as the value I stored as a variable.
I have created the following test:
pm.test(“Checking value sent in previous request is returned response”, function () {
var jsonData = pm.response.json();
pm.expect(jsonData.paymentStatus.amount.Value).to.equal(“{{value}}”);
});
However, this test is failing with AssertionError: expected 11858.74 to equal ‘{{value}}’
Could anyone advise me how I can get this assertion to work ?
You need to load the variable when you’re building your javascript tests.
pm.test(“Checking value sent in previous request is returned response”, function () {
var jsonData = pm.response.json();
let initialValue = pm.variables.get('value');
pm.expect(jsonData.paymentStatus.amount.Value).to.equal(initialValue);
});
When I copy and paste your response it returns the following warning : Expected ‘)’ and instead saw ‘value’. Missing “;” before statement. Any thoughts how to fix this ?
I’m still new to all of this so thanks for your patience.
That error would have been a formatting issue from pasting it into your app. Discourse seems to not handle the quote marks very well, when pasting the code block into another app.
Just replace the two quote marks, at either end of the test name with new ones. That should remove the error you’re seeing.