如何检查字段数据类型(只)使用邮递员?(How to check the field data ty

2019-09-29 21:39发布

我使用的邮差的几个中,我想验证从响应几个字段的数据类型(串/整数)的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  
  }
}

任何帮助,非常感谢..

谢谢

Answer 1:

您需要使用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";



文章来源: How to check the field data type (only) using postman?