Questions tagged [proxyquire]

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

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

116 questions
1
vote
0 answers

node.js : can proxyquire be applied at any level in the call stack?

Node.js : can proxyquire be be used to mock dependencies at any level in the call stack ? I need to test route1.endpoint1 route1 requires module1 , which requires module2 , which requires module3 Can I apply proxyquire to module2 -- assigning a…
BaltoStar
  • 8,165
  • 17
  • 59
  • 91
1
vote
1 answer

"require not defined" when testing with proxyquireify stubs

Hello i have a project that uses gulp for the build framework, and used karma with jasmine for the testing. I am trying to integrate proxyquireify to mock the requires, i just added proxyquireify as browserify plugin in karma config, as i am using…
Jiby Jose
  • 3,745
  • 4
  • 24
  • 32
0
votes
0 answers

How to mock response from function inside arrow function

I need to mock the response of a function being called inside an arrow function to test every line of the code. I have the following code: function foo() { return 'apiCall' } const handle = async () => { const a = await foo() if (a ==…
0
votes
0 answers

How to fix parent context unavailable when using proxyquire with ES6 import statement?

I have the following file to test which is the migration_repository.js import {getDatabaseName} from "./maria_db_connector" export default class MigrationRepository { getExistingVersions() { return getDatabaseName(); } I am trying…
piperRyan
  • 397
  • 1
  • 3
  • 11
0
votes
1 answer

Stub a function inside a function without passing it as an argument

I have the following code: const {compose} = require('./compose'); const complicatedFunction = async function (argA, argB) { const result = await getValue(argA) const value = await getValue2(argB) const composition = compose(result,…
Santeau
  • 839
  • 3
  • 13
  • 23
0
votes
0 answers

ProxyQuire Not replacing dependencies - continues to call with values assigned in the original module

myutil.ts const text = require('randtext'); // library to generate random text (example) export const myUtil = async (myId: string):Promise =>{ console.info(text.generateText()); return true; }; myutil.test.ts (this is inside a test…
Ron
  • 21
  • 1
0
votes
0 answers

When (and how) should I remove a proxyquire/sinon mock

**edit: I restored the mocked function after test1, using sinon.restore(), but again, it feels unnecessary to restore all mocks when I just want to restore one. Just wondering when and how I should remove this mocked module? It's only needed for…
NickW
  • 1,207
  • 1
  • 12
  • 52
0
votes
0 answers

Proxyquire not calling inner functions (npm modules) and does not work with classes properly

Where am i going wrong here? Using mocha, chai, sinon and proxyquire for an express server and sequelize ORM linked with a postgres database I am trying to test a login controller route from my express server Before I show the file which I want to…
Mohamed
  • 425
  • 4
  • 14
0
votes
1 answer

How to thrown error in catch block using sinon stub

I am using mocha and sinon for test the node services, In controller I have getToken npm module for getting the token with name and value as parameters and in spec file I trying to send empty name as parameter using withargs but the response getting…
0
votes
1 answer

How to force a return value from a mocked non-exported function using sinon or proxyquire or rewire?

I am just getting started unit testing nodejs. I have been using mocha, chai and sinon. I hit a snag when I wanted to test a function which is not exported. proxyquire looks good, as does rewire. There are lots of tutorials, but they tend to be…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
0
votes
1 answer

Proxyquire not overriding exported function

I have a class modules/handler.js, which looks like this: const {getCompany} = require('./helper'); module.exports = class Handler { constructor () {...} async init(){ await getCompany(){ ... } } it imports the function…
seveneights
  • 425
  • 5
  • 15
0
votes
1 answer

proxyquire Error: ENOENT: no such file or directory, scandir

Hello I am new to testing with mocha/chai/sinon and sequelize-test-helpers Trying to use proxyquire to override the require but having issues Getting this following error about the path: Error: ENOENT: no such file or directory, scandir…
Mohamed
  • 425
  • 4
  • 14
0
votes
1 answer

How to Mock non-existent file import in nodejs Lambda

I am facing issue in testing where My logger is in lambda layer thus non-existing for nodeJs import in lambda.js during mocha-chai testing. I tried mock-fs but getting errors Can not find module /opt/logger.js or maybe I am trying wrong way and not…
Vishvendra Singh
  • 484
  • 5
  • 19
0
votes
1 answer

How to mock 'request' with proxyquire

I have a file foo.js var request = require('request'); module.exports.getRequest = function (url, headers) { return new Promise((resolve, reject) => { request( { url: url, method: "GET", …
0
votes
1 answer

stub getJSON function of JQuery using proxyquire and sinon.js

I am trying to stub getJSON, done and fail function of jquery using sinon.js and proxyquire but always I am getting an error that .getJSON, done and fail is not function. const $ = require("jquery"); const Progress = (() => { const…
santosh singh
  • 27,666
  • 26
  • 83
  • 129