Skip to content

Instantly share code, notes, and snippets.

@tiagocpontesp
Created March 27, 2014 18:40
Show Gist options
  • Save tiagocpontesp/9814954 to your computer and use it in GitHub Desktop.
Save tiagocpontesp/9814954 to your computer and use it in GitHub Desktop.
var
request = require('superagent'),
nock = require('nock')
;
nock.recorder.rec();
nock.disableNetConnect();
var scope1 = nock('http://www.test.com').get('/api').reply(200);
request.get('http://www.test.com/api').end(function(err,res){
console.log('no port: '+res.status);
scope1.done();
});
var scope2 = nock('http://www.test.com:7777').get('/api').reply(200);
request.get('http://www.test.com:7777/api').end(function(err,res){
console.log('port: '+res.status);
scope2.done();
});
//************************************ STDOUT:
// $ node ports.js
// <<<<<<-- cut here -->>>>>>
// nock('http://www.test.com:80:80')
// .get('/api')
// .reply(200, "", { 'content-type': 'application/json' });
// <<<<<<-- cut here -->>>>>>
// no port: 200
// <<<<<<-- cut here -->>>>>>
// nock('http://www.test.com:7777:7777')
// .get('/api')
// .reply(200, "", { 'content-type': 'application/json' });
// <<<<<<-- cut here -->>>>>>
// port: 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment