Javascript 用点表示法连接变量
我有以上要求的摩卡测试。我想对http请求(post、get、put)使用变量requestMethod 就像上面的代码一样,我希望使用requestMethod变量而不是使用post使其可配置。如何将点符号与变量连接起来? 我用下面的代码试过了,但没有成功Javascript 用点表示法连接变量,javascript,mocha.js,concatenation,Javascript,Mocha.js,Concatenation,我有以上要求的摩卡测试。我想对http请求(post、get、put)使用变量requestMethod 就像上面的代码一样,我希望使用requestMethod变量而不是使用post使其可配置。如何将点符号与变量连接起来? 我用下面的代码试过了,但没有成功 .post(`${this.apiVersion}${apiEndpoint}) 在javascript中,您可以访问属性(奇怪的是,还有方法)作为对象数组的索引。因此,如果你这样做: '.'+requestMethod+'('+ thi
.post(`${this.apiVersion}${apiEndpoint})
在javascript中,您可以访问属性(奇怪的是,还有方法)作为对象数组的索引。因此,如果你这样做:
'.'+requestMethod+'('+ this.apiVersion + apiEndpoint +')'
它应该可以工作。什么是
请求
?请同时发布require
或import
语句。请求来自supertest库。const request=require('supertest');
'.'+requestMethod+'('+ this.apiVersion + apiEndpoint +')'
request(`http://127.0.0.1:3000`)[requestMethod](`${this.apiVersion}${apiEndpoint}`)
.set('Accept', acceptType)
.set('Content-Type', contentType)
.set('Authorization', authorization))