nock

How do I make Nock and Mocha play well together?

◇◆丶佛笑我妖孽 提交于 2021-01-27 12:27:18
问题 I am trying to use nock to intercept/mock some HTTP traffic in my application for testing purposes. Our app authenticates to another one of our sites, and I need nock to imitate an HTTP 200 (with JSON data) and an HTTP 401 (with no data) to test behaviors when the user is or isn't logged in there (respectively). I have two tests which both work correctly when run alone, but if I run the entire test suite, one of them always fails. I realize that nock is shared state because it modifies how

Unable to remove interceptors using nock

半腔热情 提交于 2020-12-06 12:32:06
问题 I am using nock and I'm trying to remove interceptors for certain hostname. I have tried using: nock.removeInterceptor({ hostname: 'somehostname.com', proto: 'https', path: '/', }), When I print the result of this, it actually gives me true I have also tried: const mock = nock(somehostname.com) .persist() .post('/endpoint') .reply(200); nock.removeInterceptor(mock) But this gives me false somehow. The way I'm checking if this is working is by printing the activeMocks: nock.activeMocks() And

Test using Nock in a scheduleJob

我是研究僧i 提交于 2019-12-24 22:46:03
问题 I'm getting a problem with test the http request in a scheduleJob node. Well, I've changed the crontime to run every second as suggested here for easier testing. The problem is, I don't think the Nock that I created to test the http request works fine. Because when I do the console.log('res : ', res); it either returns undefined or does not print anything as shown here : enter image description here. Does anyone have any idea how to solve this? Index.js schedule = require('node-schedule'),

mocking server for SSR react app e2e tests with cypress.io

巧了我就是萌 提交于 2019-12-23 01:04:20
问题 I'm building a single page web application (SPA) with server side rendering (SSR). We have a node backend API which is called both from the node server during SSR and from the browser after initial rendering. I want to write e2e tests that configures API responses (like with nock ) and work both with browser calls and SSR server calls. some pseudo-code : it('loads some page (SSR mode)', () => { mockAPI.response('/some-path', {text: "some text"}); // here i configure the mock server response

Mocking with Nock, mock only a specific route with the same host

安稳与你 提交于 2019-12-12 19:52:08
问题 I am using Nock ( https://github.com/node-nock/nock ) to mock an underly service called by an endpoint that I need to test in my application. In the implementation of the endpoint, I am calling this underly service multiple time like that : http://samehost/specificrsc1/ http://samehost/specificrsc2/ http://samehost/specificrsc3/ ... I want to know if it's possible to only mock ONE of those . Let's say this one : http://samehost/specificrsc2/ Currently i am not able to achieve that. Because I

Nock not working for multiple tests running together

筅森魡賤 提交于 2019-12-12 10:57:26
问题 I am using nock library to stub my http calls. Different test files require('nock') and do their stubbing. If each test is run separately, all is passing. But if all tests run together, later tests fail because instead of nock, actual request was made . Consider below code snippet for example. It has two different describe blocks, each with multiple test cases. If I run this file node node_modules/mocha/bin/_mocha test.js then the first two tests will pass, but the third test (in different

Error: Nock: No match for request

时光怂恿深爱的人放手 提交于 2019-12-10 15:07:57
问题 I am receiving following error { error: { Error: Nock: No match for request { "method": "GET", "url": "http://localhost:3000/admin/orders/30075889/transactions.json", "headers": { "content-type": "application/json", "host": "localhost:3000" } } Got instead { "method": "GET", "url": "http://localhost:3000/admin/orders/30075889/transactions.json", "headers": { "content-type": "application/json", "host": "localhost:3000" } } The url is as expected, not sure what's wrong, any pointer? 回答1: Use

nock is not intercepting my request

你说的曾经没有我的故事 提交于 2019-12-10 02:54:24
问题 I'm trying to create some basic tests using karma server and nock. It seems like nock is not intercepting my requests at all, does anyone have idea? I can't figure out what is missing. I still getting real data. nock('https://api.github.com/users/' + username).log(console.log) .get('/') .query(true) .reply(400, { statusMessage: 'Bad Request', foo: 'foo' }) http.get('https://api.github.com/users/' + username, function(res) { console.log('res', res) }) I also added this middleware const

Nock does not work with Nightwatch + Selenium

两盒软妹~` 提交于 2019-12-09 23:05:57
问题 I am using nock to mock my http requests. My app is written using Redux + React. import nock from "nock" nock("http://localhost:8080") .log(console.log) .get("/fake/users/sign_in.json") .reply(500, 'Error') const doLogin = (browser) => { return browser .url("http://localhost:8080") .waitForElementVisible('form', 1000) .setValue('input[name=email]', 'foo@foo.com') .setValue('input[name=password]', 'somepass') .click('button[type=submit]') .pause(500) } export default { "Do login and receive