我正在尝试在Postman中创建一个测试,以根据switch语句的结果返回不同的文本响应。但是,我不确定为什么当我单击“运行”时没有可用的测试我正确设置了我的Get方法,因为当我自己执行它时它返回例如200好的。我有以下内容:
var statMessages ;
switch (statMessages) {
case '500':
console.log('Internal Server Error.');
break;
case '200':
console.log('200 Ok');
break;
case '503':
console.log('Service unavailable.');
break;
case '502':
console.log('502 bad gateway.');
break;
case '599':
console.log('Network connect timeout error.');
break;
case '408':
console.log('Request timedout.');
break;
default:
console.log('Sorry, we are out of ' + statMessages + '.');
}
console.log("Try again?");
答案 0 :(得分:1)
如果我没有误解你的问题那么我觉得你应该这样试试。抓取您的statMessages
var statMessages = responseCode.code; // it'll return numeric code e.g 200
switch (statMessages) {
case 500:
tests["Internal Server Error."] = statMessages === 500;
break;
case 200:
tests["200 Ok"] = statMessages === 200;
break;
case 503:
tests["Service unavailable."] = statMessages === 503;
break;
case 502:
tests["502 bad gateway."] = statMessages === 502;
break;
case 599:
tests["Network connect timeout error."] = statMessages === 599;
break;
case 408:
tests["Request timedout."] = statMessages === 408;
break;
default:
tests["Sorry, we are out of" + responseCode.code]
}
答案 1 :(得分:0)