Questions tagged [nock]

Nock is an HTTP mocking and expectations library for Node.js

Nock is an HTTP mocking and expectations library for Node.js

Nock can be used to test modules that perform HTTP requests in isolation.

For instance, if a module performs HTTP requests to a CouchDB server or makes HTTP requests to the Amazon API, you can test that module in isolation.

This does NOT work with Browserify, only node.js

Documentation

252 questions
0
votes
1 answer

sinon spy as callback not being called

I have my source file for which i have written test cases for var debug = require('debug')('kc-feed:source:fb'); var request = require('request'); var config = require('../../config').root; exports.source = function fetchFeed (callback) { var…
krish
  • 43
  • 5
0
votes
0 answers

Redux testing with nock data undefined

I am using node nock to test my redux async action. The test is currently failing with the output : AssertionError: expected [ Array(2) ] to deeply equal [ Array(2) ] + expected - actual { "type": "FETCH_MOVIES" …
erichardson30
  • 4,634
  • 7
  • 21
  • 41
0
votes
0 answers

Mock 3rd party API to test express API using nock

I am trying to mock third part API which is called from my API which doesnt seem to be working. describe('Smartvehicle API test', function() { it('should return vehicle info', function(done) { nock("http://some.api.com") …
harshit
  • 7,659
  • 22
  • 66
  • 97
0
votes
0 answers

Testing Server Call in Redux / Mocha/ Nock

I'm new to testing so I'm not even sure if this is something I'm 'supposed' to be testing, but here goes: I'm following the example in https://github.com/reactjs/redux/blob/master/docs/recipes/WritingTests.md for how to write a test for an async…
0
votes
0 answers

Issue with getting Nock response into call function

I just started using nock to intercept http calls. Below is the code I am using in a unit test case after importing the required modules. it('testing superagent using nock..', function () { let mockData = { scope: this, data:…
pnsrinivasreddy
  • 203
  • 2
  • 7
0
votes
1 answer

How to mock requests with absolute path for JS testing?

In one component I sent a xhr request to '/api/somecall' I am trying to mock the HTTP request for testing purposes with MochaJS. I went into nock but the first parameter is the domain, which cannot be fixed because we use the same app on several…
Mijamo
  • 3,107
  • 1
  • 18
  • 18
0
votes
1 answer

Why is Mocha passing this https.get request?

Brand new to testing. Trying to figure out why mocha is passing this test when it should be failing. var assert = require('assert'); var nock = require('nock'); var https = require('https'); describe('thing', function() { …
Blexy
  • 9,197
  • 5
  • 35
  • 51
0
votes
1 answer

Node.js - module: nock - .reply with a callback doesn't work

I'm using nock module to intercept HTTP calls to my API service (still undeveloped) and return some mock data that I have in a temporary database. I notice the http requests are intercepted properly, but the problem that I see is that before my…
Ananth
  • 597
  • 1
  • 5
  • 15
0
votes
1 answer

Specify specific nock requests

I am looking for a way to be able to specify which nock request will be called for each mocha test. The issue is that I have ~50 nock request all with the same exact url (post data differs) and it makes using skip() and only() in mocha a huge pain.…
cyberwombat
  • 31,246
  • 30
  • 143
  • 210
0
votes
1 answer

Nock intercepts the HTTP POST requests and hangs during testing Mocha/Node.js module in CoffeeScript

I am wondering if you have experienced the situation where the 'nock' module intercepts the http request but stops without any logging...at least, that appears to me. I may be wrong. Here is the test: ... suite('Successful SAVE: ', function(){ …
latvian
  • 2,881
  • 9
  • 30
  • 57
-1
votes
1 answer

How to make Dotenv and Nock work together?

Currently in one of my apps i am using nock to mock my api request.Unfortunately in another test file of same project, i used dotenv.If i use dotenv my nock is not mocking the url, it is using the original api request. Any suggestions or help is…
-2
votes
1 answer

How to mock HTTP request. I am using the NPM request package. Nock doesn't seem to work

I am trying to use Nock. It is matching the URL as per my mock definition. Though the problem is that my actual request is failing. And I am not being able to test for my response that I am setting up using Nock. My nock definition looks like…
Neo
  • 195
  • 1
  • 8
1 2 3
16
17