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
1 answer

How to mock module function using proxyquire

I need to mock 'mkdirp-promise' node module which exposes a constructor function as below mkdirpPromise(dirPath) .then(() => { console.log('ABCDEFGH'); resolve(dirPath); }) .catch((error) => { …
iAviator
  • 1,310
  • 13
  • 31
1
vote
1 answer

Proxyquire: Cannot Stub Cassandra-driver

I am trying to mock Cassandra for unit test cases , I am using npm Cassandra-driver for connecting/querying cassandra. for mocking the stub this is my code. beforeEach(function () { let CassandraClient = sinon.stub(); …
user3649361
  • 944
  • 4
  • 20
  • 40
1
vote
1 answer

What Path is the Babel Plugin module-alias Actually Using?

I'm trying to use Babel's "module-alias" plug-in with the "proxyquire" testing library, but I'm not having a lot of luck. Library Backstory (feel free to skip if you are familiar with both module-alias/proxyquire) Proxyquire let's you mock out a…
machineghost
  • 33,529
  • 30
  • 159
  • 234
1
vote
1 answer

Proxyquire: Cannot Stub fs.readFileSync

I seem unable to stub readFileSync on fs from the NodeJS core. The following code isolates the issue. Running the test via Mocha results in the following: > mocha tests/test.js Some description 1) "before all" hook 0 passing…
Andrew
  • 6,144
  • 10
  • 37
  • 54
1
vote
2 answers

Writing tests for async.parallel.

I am a newbie to javascript.I am trying to write a basic unit test using proxyquire. for below code. file A: const modA=require('./modA'); const modB=require('./modB'); const…
1
vote
1 answer

node.js proxyquire stub asynchronous function from module required by another module

Module under test: 'use strict'; const config = require('config'); const q = require('q'); class RedisAccess { static getValue(key) { let deferred = q.defer(); if (config.redis.disableInteraction) { …
sizzle
  • 2,222
  • 2
  • 21
  • 32
1
vote
2 answers

Testing a function that calls a function that returns a promise

I have code in the following form: sut.methodtotest = param => { return dependency.methodcall(param) .then((results) => { return results; }); }; I want to test sut.methodtotest, but when I use chai, mocha, require,…
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
1
vote
0 answers

Proxyquire module is not taking the changes made to the file properly

I have made some changes to my file "config.js" which is required in the nmodule to be tested "file.js". fileTest.js : __________________________ var file = require("file"); var proxyquire = require("proxyquire").noPreserveCache(); var…
Surya
  • 628
  • 3
  • 9
  • 26
1
vote
0 answers

proxyquire TypeError when not replacing every function in a module

I'm trying to use proxyquire to unit test my Redux reducers. I need to replace the functionality of one function in my test but keep the original functionality of the other, which is possible according to proxyquire's…
kibowki
  • 4,206
  • 16
  • 48
  • 74
1
vote
1 answer

Node Stub a method that returns an object

I have a module that has some properties. I am using it as below Var propmodule = require('me-props'); var prop = new propmodule('server'); prop.get('min); //returns 3 prop.get('max') //returns 10 I have to mock this for testing. Did the below code…
Shabin Hashim
  • 677
  • 1
  • 10
  • 23
1
vote
1 answer

How to stub a nodejs "required" constructor using sinon?

I'm writing unit tests for a method that uses the email-templates module like this: var EmailTemplate = require('email-templates').EmailTemplate; module.exports = { sendTemplateEmail: function (emailName, data, subject, to, from) { var…
Jared
  • 2,043
  • 5
  • 33
  • 63
1
vote
1 answer

See where function is defined

How can I see where this function: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#copyObject-property copyObject(params = {}, callback) ⇒ AWS.Request is defined? What I tried: var AWS =…
John Smith
  • 6,105
  • 16
  • 58
  • 109
1
vote
1 answer

Node unit tests - TypeError: Cannot read property 'order' of undefined

I'm getting the following error, Error: BLANKET-Error parsing instrumented code: TypeError: Cannot read property 'order' of undefined in my test code indicating the line where testedModule = proxyquire('../index', {. Can anyone see why I am getting…
hyprstack
  • 4,043
  • 6
  • 46
  • 89
1
vote
1 answer

Targeting nested method with sinon and proxyquire

For the following snippet of nodejs code, how would I stub the send method using proxyquire and sinon, given that this belongs to file index.js? I have tried many ways but constantly get errors. var emailjs =…
hyprstack
  • 4,043
  • 6
  • 46
  • 89
1
vote
1 answer

Proxyquire can't find module

I'm trying to use proxyquire to mock dependency for testing. But I keep getting this error Cannot find module I tried with full path and it's still complaining. I have a src file which is in assets/js/src/lib and the test in js-tests/specs Here's…
toy
  • 11,711
  • 24
  • 93
  • 176