In node.js, I have trouble making superagent and nock work together. If I use request instead of superagent, it works perfectly.
Here is a simple example where superagent fails to report the mocked data:
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);
});
the res object has no 'text' property. Something went wrong.
Now if I do the same thing using request:
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)
}
})
The mocked content is displayed correctly.
We used superagent in the tests so I'd rather stick with it. Does anyone know how to make it work ?
Thank's a lot, Xavier