如何使用邮递员检查字段数据类型(仅)? [英] How to check the field data type (only) using postman?
问题描述
我正在使用Postman进行一些API验证,在这些验证中,我想从响应中验证几个字段的数据类型(字符串/整数).我不想检查字段值. 例如:如果收到类似以下的响应,我想检查一下sign_in_count是否总是返回整数数据类型. :
I am using Postman for few of the API verifications in which I would like to verify data type (string/integer) of few fields from the responses. I do not want to check the field value. Ex:If I get a response something similar as below, I would like to check that sign_in_count always returns integer data type. :
{
"data": {
"id": 274,
"age": null,
"email_id": "ojuuw@mailinator.com",
"email_verification_flag": true,
"ext_account": null,
"ext_authenticator": null,
"ext_user_id": null,
"firstname": "firstname",
"forgot_password_sent": null,
"gender": null,
"last_sign_in_at": null,
"last_sign_in_ip": null,
"region": "IN",
"registered_using": null,
"remember_created_at": null,
"reset_password_sent_at": null,
"reset_password_token": null,
"sign_in_count": 0
}
}
任何帮助,不胜感激.
谢谢
推荐答案
您需要使用typeof
函数,该函数返回未求值操作数的类型.
You need to use typeof
function which returns the type of unevaluated operand.
var body = JSON.parse(responseBody);
tests["sign_in_count is number"] = typeof(body.data.sign_in_count) === "number";
tests["firstname is string"] = typeof(body.data.firstname) === "string";
var body = JSON.parse(responseBody);
tests["sign_in_count is number"] = typeof(body.data.sign_in_count) === "number";
tests["firstname is string"] = typeof(body.data.firstname) === "string";
这篇关于如何使用邮递员检查字段数据类型(仅)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!