Tag: superagent

superagent和nock怎么能一起工作?

在node.js中,我很难使superagent和nock一起工作。 如果我使用请求,而不是superagent,它完美的作品。 这里是一个简单的例子,superagent不报告模拟的数据: var agent = require('superagent'); var nock = require('nock'); nock('http://thefabric.com') .get('/testapi.html') .reply(200, {yes: 'it works !'}); agent .get('http://thefabric.com/testapi.html') .end(function(res){ console.log(res.text); }); res对象没有“text”属性。 出了些问题。 现在,如果我使用请求做同样的事情: var request = require('request'); var nock = require('nock'); nock('http://thefabric.com') .get('/testapi.html') .reply(200, {yes: 'it works !'}); request('http://thefabric.com/testapi.html', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body) […]

在node.js服务器上读取supertest / superagent的响应输出缓冲区/stream

我正在尝试编写一个testing,检查API路由是否输出正确内容的ZIP文件。 我正在使用mocha和supertest进行testing,我想实际读取输出stream/缓冲区,读取zip文件的内容,看看内容是否正确。 任何想法我应该怎么做? 当我尝试阅读res.body ,它只是一个空的对象。 request(app) .get( "/api/v1/orders/download?id[]=1&id=2" ) .set( "Authorization", authData ) .expect( 200 ) .expect( 'Content-Type', /application\/zip/ ) .end( function (err, res) { if (err) return done( err ); console.log( 'body:', res.body ) // Write the temp HTML file to filesystem using utf-8 encoding var zip = new AdmZip( res.body ); var zipEntries […]

你怎么能用superagent来使用cookies?

我正在用类似这样的快递进行cookie会话pipe理: req.session.authentication = auth; 我用类似的东西来validationauthentication的url if(!req.session.authentication){res.send(401);} 现在我正在用摩卡, superagent和应该build立testing,但是我似乎无法find一种方法来获取/设置与superagent的cookie。 我甚至试图在authenticationtesting之前请求login,但它不工作, 我已经尝试在摩卡BDD套件的before语句中将请求添加到login中,但是它仍然告诉我该请求是未经授权的,我已经testing了从浏览器执行请求的身份validation,但是它不能从套房有什么想法?