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
0 answers

Testing RxJS requests with nock

Say I had a function defined like so: import {RxHR} from '@akanass/rx-http-request' (arg) => RxHR.get(`https://third.party.com/${arg}`) .take(1) .pluck('body') .map(JSON.parse) I now wish to test this function (call it importedFunction)…
Abraham P
  • 13,493
  • 11
  • 50
  • 108
0
votes
1 answer

How to get the name of a request via Nock object

At the point in my test code where I check assert that all nocks have been called, I have a semi-useful error message to dumps out if a nock wasn't called (since the default error message is useless): try { assertions(data, result); if…
Matthew Herbst
  • 21,357
  • 19
  • 68
  • 107
0
votes
0 answers

Nested request not succeeding while using nock

I have defined the following simple function and I want to test this using nock. function checkJobAndUpload(ycgResponse, targetJob, integrationId, jobBoardId, callback) { const options = { uri:…
maddy
  • 13
  • 1
  • 5
0
votes
1 answer

Nock, localhost, port, and redux-observable

I have a mock api setup with node/express http://localhost:8080/api/lyric/ I'm using redux-observable to fetch the json: const fetchLyricEpic = action$ => action$.ofType(FETCH_LYRIC) .mergeMap(action => ajax.getJSON('/api/lyric') …
redconservatory
  • 19,528
  • 37
  • 112
  • 184
0
votes
1 answer

Unable to write Redux tests for action creators

ORIGINAL QUESTION I'm following the example for writing tests for async action creators spelled out in the Redux documentation. I'm following the example as closely as possible, but I can't get the test to work. I'm getting the following error…
Anup Sheth
  • 229
  • 1
  • 2
  • 11
0
votes
2 answers

Why we need nock to do http request unit test?

Below is the sample code from redux document describe('async actions', () => { afterEach(() => { nock.cleanAll() }) it('creates FETCH_TODOS_SUCCESS when fetching todos has been done', () => { nock('http://example.com/') …
Dreams
  • 6,942
  • 7
  • 37
  • 57
0
votes
1 answer

How to get the response from nock

I've been writing some unit tests and I noticed that I can't seem to find a good way to test asynchronous functions. So I found nock. It seems cool, only if it worked. I'm clearly missing something... import nock from 'nock'; import request from…
Modelesq
  • 4,400
  • 15
  • 52
  • 76
0
votes
2 answers

Why is nock matching request when body, time and timeout should not match?

I have a service request nocked, I expect a nock error (nock: No match for request POST) in this case but getting a successful response. wondering why! nock(`http://localhost`, { reqheaders: { 'Content-Type':…
binndur
  • 11
  • 1
  • 4
0
votes
1 answer

Nock - Bodies don't match

Why does Nock give me an error saying that bodies don't match?? here is my code. it('Should Delete /user/removeuserskills', function(done){ mockRequest .delete('/user/removeuserskills',{skill:'accountant'}) .reply(201,{ …
user3450754
  • 115
  • 1
  • 1
  • 11
0
votes
1 answer

nock,mocha,testing Uncaught AssertionError:

this is my function called lifestyle var url="http://blah/get/[type]/[id]"; function lifeStyle(req,res){ var dataEnter={ 'id':1797, 'type':'lifestyle' } var p = promiseStyle(dataEnter); p.then(function(data) { …
mary
  • 19
  • 1
  • 7
0
votes
1 answer

Nock is intercepting my request, but my AJAX request is erroring out

I'm testing an AJAX request made using XMLHttpRequest: export default function requestToTest() { const xhr = new XMLHttpRequest(); xhr.open('GET', 'https://example.com/service'); xhr.onload = () => { console.log('onload'); // etc. …
Kevin
  • 11,714
  • 18
  • 66
  • 107
0
votes
1 answer

Loading nock on intern

I am trying to use nock (https://github.com/node-nock/nock) in my tests. If I write var nock = require('nock'); it won't find it as it is not loaded. I have added the package in loaderOptions, and now I have to put var nock = require('nock/index');,…
QuarK
  • 1,741
  • 1
  • 15
  • 23
0
votes
1 answer

Mocking NodeJS request and response with Nock

I'm trying to get the grasp of the tool Nock in order to mock the request and response from my code doing the calls. I'm using npm request as a simple HTTP client to request the back-end REST API, Chai for the expectation library and Mocha to run my…
Nizar B.
  • 2,767
  • 9
  • 32
  • 52
0
votes
2 answers

What is the purpose of using a mock ajax call in testing?

I'm learning about TDD React here and don't understand the below test situation: it('Correctly updates the state after AJAX call in `componentDidMount` was made', (done) => { nock('https://api.github.com') .get('/users') .reply(200, [ …
stackjlei
  • 7,747
  • 12
  • 42
  • 95
0
votes
1 answer

Testing Express route where that route has a callback

I want to mock a curl request to an express route that calls an api. I've found a lot of documentation on how to do this but I've been having issues because there is a call back in my code. var request = require('request') function…
cmslotes
  • 1
  • 1
1 2 3
16
17