Comments (12)
Hi @mgcrea, can you please give me a snippet of code that fails?
Thanks!
from nock.
Hi @pgte, it's really basic, and i get the issue even with http (but there is a 301 to https).
beforeEach(function() {
player = new Player({
...
});
host = 'http://dev.carlipa-online.com';
scope = nock(host)
.get('/pull/debug:1', '*')
.reply('404');
});
from nock.
According to this stackoverflow question
I've seen this happen when your host (which you pass in as httpaction) has the scheme (so "http://") in front of it. Your host should strictly be the domain like "www.google.com" not "http://www.google.com" or "www.google.com/hello-world" or "http://www.google.com/hello-world".
from nock.
I tried using the following code with node v0.8.9 in OSX and it works.
var nock = require('nock');
var request = require('request');
host = 'http://dev.carlipa-online.com';
scope = nock(host)
.get('/pull/debug:1')
.reply('404');
request('http://dev.carlipa-online.com/pull/debug:1', function(err) {
console.log('got resp', arguments);
});
Does this work for you? If so, can you make it break?
Thanks for your help.
from nock.
This does work for me!
I'm using jasmine-node
so it may come from this.
I had not use the request
module before.
My call looked like :
this.request = https.request(this.requestOptions, function(response) { ....
I'll try to provide a better unit test to reproduce it.
from nock.
The code below does not work & returns :
Error: Nock: No match for HTTP request GET /pull/debug:1
Code :
describe('player', function () {
var player, host, scope;
beforeEach(function() {
host = 'http://dev.carlipa-online.com';
scope = nock(host)
.get('/pull/debug:1', '*')
.reply('404');
});
it('should be able to perform a pull', function(done) {
request('http://dev.carlipa-online.com/pull/debug:1', function(err) {
console.log('got resp', arguments);
});
setTimeout(function() {
scope.done();
}, 2000);
});
});
from nock.
That's a diff problem.
You're doing
.get('/pull/debug:1', '*')
and should be doing:
.get('/pull/debug:1')
from nock.
Thanks for spotting that out, it worked. This is not working (got close to the real call) :
beforeEach(function() {
host = 'https://dev.carlipa-online.com';
scope = nock(host)
.post('/pull/debug:1')
.reply('404');
});
it('should be able to perform a pull', function(done) {
/*request('http://dev.carlipa-online.com/pull/debug:1', function(err) {
console.log('got resp', arguments);
done();
});*/
var postData = querystring.stringify({foo: 'bar'});
var requestOptions = {
host: 'dev.carlipa-online.com',
port: 443,
path: '/pull/debug:1',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
}
};
var request = https.request(requestOptions, function(response) {
console.log('got resp', arguments);
done();
});
request.write(postData);
request.end();
setTimeout(function() {
scope.done();
}, 2000);
});
But no getaddrinfo
error so far.
Just Error: Nock: No match for HTTP request POST /pull/debug:1 foo=bar
from nock.
This error is a mismatch.
You should be matching something like .post('/pull/debug:1', JSON.stringify({foo: 'bar'}))
I'm closing this for now, please reopen if you find something that is not covered in https://github.com/flatiron/nock#readme
Thanks.
from nock.
Yep, just found out that. Will try to produce a clean test case for the getaddrinfo error before bothering you again. Sorry for that & thank you for your help.
from nock.
Yup, preferably a plainvanilla node script I can run directly.
Thanks.
from nock.
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!
from nock.
Related Issues (20)
- [Node 18.12] Class extends value undefined is not a constructor or null HOT 2
- incompatible behaviour introduced with v13.3.2 HOT 17
- Interceptors not being removed in 13.3.2 HOT 2
- Replace npm debug with require('node:util').debuglog HOT 2
- Remove lodash HOT 1
- Application to become a nock maintainer. HOT 5
- Expand function fails on weird GET query params HOT 4
- reqheaders does not work when using an undefined requestBody HOT 3
- Add interceptor at the beginning of list
- Return 500 instead of 404 HOT 4
- Bun support for nock.disableNetConnect() HOT 1
- DNS resolve errors and not mocking a lot of requests HOT 7
- POST request with ReadStream request body does not return a response HOT 10
- Disabled discussions HOT 6
- Improve debug logging HOT 2
- Support Abort Signals HOT 1
- Add JSDoc HOT 8
- Using nock inside a stream pipeline with got causes it to hang forever since Node 20.10.0 HOT 2
- Debug logging broken in beta (14.0.0-beta.5) HOT 1
- Error when code cancels fetch response body stream (14.0.0-beta.6) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nock.