Questions tagged [proxyquire]

Questions regarding proxyquire - Proxies nodejs's require to make overriding dependencies during testing

Documentation: https://github.com/thlorenz/proxyquire

116 questions
0
votes
0 answers

How to stub google-apis methods?

I'm using Gmail API, Now I try to stub gmail.users.threads.list method for test cases. But it doesn't work. I tried: const { google } = require('googleapis'); const gmail =…
Surya S
  • 53
  • 8
0
votes
1 answer

How to mock Mongo find using Sinon and Proxyquire

I have the below Middleware class which I want to unit test: const jwt = require('jsonwebtoken'); const config = require('../config/auth.config.js'); const db = require('../models'); const User = db.user; const Role = db.role; isAdmin = (req, res,…
Juan Ga
  • 87
  • 5
0
votes
1 answer

Sinon stub not working when proxyquire is used

I am writing tests for express APIs. I use proxyquire to stub module.exports = someFunction() type of dependency. I have a protected route, so I used proxyquire to stub auth middleware.This auth middleware is being stubbed.In the controller I have a…
sujeet
  • 3,480
  • 3
  • 28
  • 60
0
votes
1 answer

Mocking runtime config value with sinon

I am adding some config values before hapi server start. Application is works fine although in test I can not use config.get(). I can get around with proxyquire. So I was wondering Is adding config file "dynamically" is bad design? Is there a way I…
αƞjiβ
  • 3,056
  • 14
  • 58
  • 95
0
votes
1 answer

Unable to new object returned from proxyquire

I am trying to test an object using proxyquire. The object is a simple JavaScript / TypeScript class with some dependencies. I am using proxyquire with sinon to override those dependencies and that's working fine. but I can't create new instance of…
0
votes
1 answer

proxyquire not stubbing static methods - nodejs

i have two classes ValidationHelper, BeneficiaryHelper with a static method each which i am trying to mock using proxyquire but on running npm test its giving me error: TypeError: Cannot read property 'checkMandatory' of undefined typescript file…
Sana.91
  • 1,999
  • 4
  • 33
  • 52
0
votes
1 answer

Proxyquire : Proxy-require yargs and pass values to it

I have a code as below src/example.js: var argv = require('yargs') .usage('service 1.\nUsage: $0 -s [host] -n [port]') .alias('s', 'host') .alias('n', 'port') .describe('host', 'Hostname to be used') .describe('port', 'Port on which service will…
user1452759
  • 8,810
  • 15
  • 42
  • 58
0
votes
0 answers

Sinon stub block of http post request inside non-exported function in node.js

I had a block of post request for which I need to stub response inside non-exported function as mentioned below: function callMicroserive(a, b, c){ //before post request code part request.post(requestoptions, function (error, httpResponse, body)…
Nazeer_hanne
  • 213
  • 6
  • 20
0
votes
1 answer

mock require of oracledb using proxyquire to unit test node.js app

Please help to fix the below issue: I am trying to unit test the dbAdapter module using mocha. dbAdapter to connect to oracle and execute sql commands (dbAdapter.js) const oracledb = require('oracledb'); let doConnect = function(callback) { …
MANOJ
  • 716
  • 4
  • 10
  • 29
0
votes
1 answer

stub doesn't return the resolve data in proxyquire getting undefined

i am not able get the resolved value in the response the promise stub returns undefined otpHelper.sendOtp = (number) => { console.log('number', number); return Promise.resolve({ status: '0', requestId: 'hdgfhsgdfdsgfjsgdfj'…
zabusa
  • 2,520
  • 21
  • 25
0
votes
1 answer

Node.js - unit test for function with mocked promise inside

I'm currently making a small server in JavaScript and as part of the learning process I'm writing unit tests for the functions. Unfortunately I ran into major difficulties with a certain test that handles a promise. Below is the router module, with…
user3529379
  • 159
  • 2
  • 11
0
votes
0 answers

How to test a function that is part of an object created by a required module in nodejs?

I have this module and the corresponding test with proxyquire. // sqlQuery.js const sql = require('mssql'); module.exports = function sqlFn() { const request = new sql.Request(); } // sqlQueryTest.js const proxyquire =…
jota
  • 3
  • 2
0
votes
1 answer

Enzyme unit test to type of HOC component with proxyquire

I've got a function that return depends on parameters HOC componetns. I wrraped this component to reduxForm HOC. I would like to test it with an enzyme using type(). The function returns HOC components with type FormValues, but how to return for…
Palaniichuk Dmytro
  • 2,943
  • 12
  • 36
  • 66
0
votes
1 answer

Proxyquire does not stub

I'm trying to use proxyquire to stub the spawnSync method of the child_process module, but it doesn't work. The console.log(gitResponse) in my index.js file doesn't return the stubbed string, but the unstubbed response (in this case, the git help…
jonsanders101
  • 525
  • 1
  • 6
  • 13
0
votes
2 answers

nodejs - sinon stub not being called

For some reason I am having a little trouble getting this simple test to run correctly with a similar set-up I have used multiple times before. Perhaps a fresh pair of eyes could help me understand why my method generateReport is not being invoked…
hyprstack
  • 4,043
  • 6
  • 46
  • 89