如何使用邮递员检查字段数据类型(仅限)?

Ash*_*ini 1 api types postman

我正在使用Postman进行一些API验证,其中我想验证响应中几个字段的数据类型(字符串/整数).我不想检查字段值.例如:如果我得到类似下面的响应,我想检查sign_in_count总是返回整数数据类型.:

    {
  "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  
  }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助,非常感谢..

谢谢

Din*_*mar 5

您需要使用typeof返回未评估操作数类型的函数.

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";