cmotto
cmotto

Reputation: 28

Comparing string value to .json data for API test in Postman

pm.test("Correct Asset Returned", 
function () {
var jsonData = pm.response.json();
pm.expect(jsonData.AssetId).to.equal(pm.variables.get("AssetNumber"));});

I get this error. (The test should pass) :

AssertionError: expected 315 to equal '315'**

Upvotes: 0

Views: 2124

Answers (1)

Yevhen Laichenkov
Yevhen Laichenkov

Reputation: 8652

It because the type of the AssetNumber variable is the String and the type of the AssetId is the Number. So you should convert to string or to number one of them before verify it.

pm.expect(`${jsonData.AssetId}`).to.equal(pm.variables.get("AssetNumber"));});

or

pm.expect(jsonData.AssetId).to.equal(Number(pm.variables.get("AssetNumber")));});

Upvotes: 2

Related Questions