Questions tagged [proxyquire]

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

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

116 questions
2
votes
1 answer

TypeError: AWS.SecretsManager is not a constructor in unit testing with proxyquire

I have written a test code to test code that gives credentials from AWS Secret Manager. I used proxyquire and sinon for stubbing and getting this error. Function I want to test exports.getCredsFromAWSSecretsManager = (keyName) => { const SM…
2
votes
1 answer

How to mock a configuration dependency in TypeScript with Proxyquire?

I have a config.ts which returns an object: // Config is an interface that I use to know which values are expected export default function getConfig(): Config { return {amount: 50} } I have a class (../src/models/item.model) that has a…
2
votes
0 answers

Proxyquire and Sinon to check if function is called

I'm trying to write a test within a file called fooTest that's trying to check if, in the file foo, when I call fooHandler, a function in the file bar is called. I've been able to test that the function in bar is called. (barSpy = sinon.spy(), and…
user319407
  • 173
  • 1
  • 2
  • 4
2
votes
1 answer

How to mock nested dependencies in NodeJS

I have a Module a const b = require(./b); function aGetResult() { return b.getInfo(); } Module B const c = require(./c); function getInfo() { return getDetailInfo(); } function getDetailInfo() { const result = c.getApiResult(); …
jbs87
  • 55
  • 6
2
votes
1 answer

can't mock constructor using sinon and proxyquire

I've looked at several similar questions but none of the cases fit my problem. I'm trying to mock a constructor, which I've done in other tests, but I can't get it to work in the case of using google-auth-library code.js const {OAuth2Client} =…
Ari
  • 23
  • 1
  • 3
2
votes
0 answers

Unit testing using sinon stub promise and axios

I am trying to test my node js api using sinon. I have a function appRequest() that returns the appDetails; but I am not able to get the result. I am using proxyquire to get the result but its not working. appService.js function…
c4cloud
  • 29
  • 3
2
votes
2 answers

Proxyquire not stubbing

I'm trying to get Proxyquire to work with a simple method substitution but I can't figure out what I'm doing wrong. I create lib.js module.exports = { thing: () => { console.log("thing"); } }; And test.js const lib =…
Retta
  • 61
  • 4
2
votes
1 answer

How to bind a helper stub to swagger-node with supertest?

I am using Swagger Node with express and I initialized the skeleton project. Swagger project create hello-world Then inside the hello-world/api/controllers/hello_world.js I added a small modification to require a helper hello_helper.js and call its…
Quinma
  • 1,436
  • 2
  • 17
  • 39
2
votes
1 answer

Nodejs mocking a method

I want to make a stub of the getDbmodel method. It is defined in basemodel.js which is import Sequelize from 'sequelize'; import db from '../../config/database'; let instance = null; class Database { static getDbmodel = () => { if…
2
votes
1 answer

google-geocoder with proxyquire and sinon

I'm still very much learning node, js, sinon, proxyquire, etc. I have a module that uses the google-geocode module (https://github.com/bigmountainideas/google-geocoder) and I am struggling to write a test to stub it. This all boils down I think to…
s27840
  • 367
  • 1
  • 5
  • 14
2
votes
2 answers

Prevent calling of local imported modules with Jest

Code I'm working with: // redux-reducer.js import { combineReducers, loop, Effects } from 'redux-loop' import { loginStart } from './actions' import { signUp, login, refreshAccessTokenStart, replayAction, postConfirmationToken, …
Pete
  • 35
  • 1
  • 9
2
votes
0 answers

Strategy for using proxyquire to mock requires across multiple testing files (NodeJS)

I am using a Redis cache in a few API files, meaning I have a dependency that I need to mock in tests. Let's say I have the following file structure -api - login.js * - login.spec.js - initiate.js - initiate.spec.js - user.js * -…
MDalt
  • 1,681
  • 2
  • 24
  • 46
2
votes
1 answer

Stubs and proxquire

I'm having an issue with stubbing a particular function with sinon after having used proxyquire. Example: // a.js const api = require('api'); module.exports = (function () { return { run, doStuff }; function run() { …
kjonsson
  • 2,799
  • 2
  • 14
  • 23
2
votes
1 answer

Prevent proxyquire to call original code?

I am trying to test around a mongoose model. I use proxyquire to mock it integrally, but since the original file register the model, I get OverwriteModelError: Cannot overwrite `EEG` model once compiled. Since everything I need is already…
DrakaSAN
  • 7,673
  • 7
  • 52
  • 94