Nocked calls to nested HTTP calls not working as expected
See original GitHub issueHere’s a sample app:
var express = require('express');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var request = require('request');
var app = express();
var PORT = 1234;
app.set('port', PORT);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.get('/test', function (req, res) {
request.get('http://www.google.com', function (err, response, body) {
res.send(body);
});
});
app.listen(PORT, function () {
console.log('App started on port ' + PORT + '!');
});
Here’s the Mocha test for it:
var mocker = require('nock');
var assert = require('chai').assert;
var request = require('request');
describe('node-nock', function () {
var testOutput = 'Hooray!';
mocker('http://www.google.com')
.get('/')
.reply(200, testOutput);
it('should mock the request to google.com', function (done) {
request('http://localhost:1234/test', function (err, response, body) {
assert.equal(testOutput, body);
done();
});
});
});
Running the test above fails the assertion even though the call to www.google.com has been nocked.
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (1 by maintainers)
Top Results From Across the Web
Angular 6 Nested HTTP Calls Nested Call Never Executes
If I break up the two calls and execute them individually they both work. However, when combining them in series the second call...
Read more >nock - npm
HTTP server mocking and expectations library for Node.js. Nock can be used to test modules that perform HTTP requests in isolation.
Read more >The Best Smart Smoke Alarm | Reviews by Wirecutter
Smart smoke alarms are pricey, but unlike traditional ones can alert you to a problem even when you aren't home. The Google Nest...
Read more >Nesl: A Nested Data-Parallel Language (Version 3.1)
compiler, on a local workstation while executing interactive calls to Nesl programs on ... solves the problem of nding the k th smallest...
Read more >Never use nested IFs again! : r/excel - Reddit
Not the IFERROR call. Another place IF constructs can't be replaced is array formulas. Maybe no one should use array formulas either, but...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@vitorarins @matanh-tzmedical Many thanks for your responses. No, I wasn’t requiring the app in my test, and yes, I was running the app separately.
Yes, I’m happy for this issue to be closed.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!