我正在尝试为我们设置一个测试,以验证被用户名和密码的基本身份验证阻止的路径的用户名和密码。it('shouldreceiveastatuscodeof200withlogin',function(done){request(url).get("/staging").expect(200).set('Authorization','Basicusername:password').end(function(err,res){if(err){throwerr;}done();});}); 最佳答案 使用认证方法SuperTest基于Su
我正在尝试为我们设置一个测试,以验证被用户名和密码的基本身份验证阻止的路径的用户名和密码。it('shouldreceiveastatuscodeof200withlogin',function(done){request(url).get("/staging").expect(200).set('Authorization','Basicusername:password').end(function(err,res){if(err){throwerr;}done();});}); 最佳答案 使用认证方法SuperTest基于Su
我有一个非常简单的Koa应用程序:varapp=module.exports=require("koa")();app.use(function*(){this.body="KoasaysHi!";});varport=process.env.PORT||(process.argv[2]||3000);port=(typeofport==="number")?port:3000;app.listen(port);console.log("Applicationstarted.Listeningonport:"+port);我像这样用mocha和supertest进行测试;varapp=
我有一个非常简单的Koa应用程序:varapp=module.exports=require("koa")();app.use(function*(){this.body="KoasaysHi!";});varport=process.env.PORT||(process.argv[2]||3000);port=(typeofport==="number")?port:3000;app.listen(port);console.log("Applicationstarted.Listeningonport:"+port);我像这样用mocha和supertest进行测试;varapp=
我正在尝试使用supertest进行一些测试。这是我要测试的代码片段:it("shouldcreateaneworgwithvalidprivilegesandinputwithstatus201",function(done){request(app).post("/orgs").send({name:"new_org",owner:"oldschool@aol.com",timezone:"America/New_York",currency:"USD"}).expect(201).end(function(err,res){res.body.should.include("new
我正在尝试使用supertest进行一些测试。这是我要测试的代码片段:it("shouldcreateaneworgwithvalidprivilegesandinputwithstatus201",function(done){request(app).post("/orgs").send({name:"new_org",owner:"oldschool@aol.com",timezone:"America/New_York",currency:"USD"}).expect(201).end(function(err,res){res.body.should.include("new
我正在使用Supertest和Mocha来测试使用NodeJS开发的API。我想对API做很多不同的测试。对于几乎所有这些,我必须再次设置Authorization和Content-Typeheader(因为API需要它们进行此测试)。it('Creationwithoutanemailaddressshouldfailandreturnerrorcode50040',function(done){request.post('/mpl/entities').set('Authorization','Token1234567890')//setheaderforthistest.set(
我正在使用Supertest和Mocha来测试使用NodeJS开发的API。我想对API做很多不同的测试。对于几乎所有这些,我必须再次设置Authorization和Content-Typeheader(因为API需要它们进行此测试)。it('Creationwithoutanemailaddressshouldfailandreturnerrorcode50040',function(done){request.post('/mpl/entities').set('Authorization','Token1234567890')//setheaderforthistest.set(
我正在Express中构建一个RESTAPI,我试图在我的Jasmine单元测试中模拟Redis(使用redis-mock)。如果supertest正在向API发出请求,我如何告诉我的应用程序使用模拟Redis而不是实际的Redis?.我知道我可能需要为我可以以某种方式换出的redis创建单独的模块,只是不确定如何将其换出以用于常规请求和super测试请求。单元测试:describe('InstanceAPIv1',()=>{it('returnsalistofinstances',(done)=>{request(app.default).get('/v1/instance').se
我试图使用Node.jssupertest来测试我编写的一些RESTAPI。我需要发送一个等效于以下CURL请求的请求:curl-XPOST-Fapi_key=KEY-Fimage=@my_filehttp://localhost:3000/v1/upload我尝试了以下方法,但得到UncaughtTypeError:firstargumentmustbeastringorBuffer。request.post('/v1/upload').type('form').field('api_key','abcd').attach('image','somepath').end(functi