Giter VIP home page Giter VIP logo

Comments (12)

pgte avatar pgte commented on July 21, 2024

Hi @mgcrea, can you please give me a snippet of code that fails?

Thanks!

from nock.

mgcrea avatar mgcrea commented on July 21, 2024

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.

mgcrea avatar mgcrea commented on July 21, 2024

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.

pgte avatar pgte commented on July 21, 2024

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.

mgcrea avatar mgcrea commented on July 21, 2024

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.

mgcrea avatar mgcrea commented on July 21, 2024

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.

pgte avatar pgte commented on July 21, 2024

That's a diff problem.
You're doing

.get('/pull/debug:1', '*')

and should be doing:

.get('/pull/debug:1')

from nock.

mgcrea avatar mgcrea commented on July 21, 2024

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.

pgte avatar pgte commented on July 21, 2024

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.

mgcrea avatar mgcrea commented on July 21, 2024

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.

pgte avatar pgte commented on July 21, 2024

Yup, preferably a plainvanilla node script I can run directly.

Thanks.

from nock.

lock avatar lock commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.