proxyquire not stubbing static methods - nodejsHow do I test a private function or a class that has private methods, fields or inner classes?What's the difference between faking, mocking, and stubbing?How to mock void methods with MockitoHow can I update NodeJS and NPM to the next versions?Stubbing with proxyquireUsing proxyquire to stub require in 3rd party modules dependencyBabel unexpected token import when running mocha testsproxyquire not stubbing method callstubbing a function in a proxyquired objectProxyquire: Cannot Stub fs.readFileSync

Need help figure out a Fibonacci related math trick

1kV DC Circuit - Insulation on ground wire?

Can you create water inside someone's mouth?

In apex, how to replace the value in the string

First Number to Contain Each Letter

How to measure the statistical "distance" between two frequency distributions?

Male viewpoint in an erotic novel

I won a car in a poker game. How is that taxed in Canada?

Is there a name for categories whose objects are sets?

What drugs were used in England during the High Middle Ages?

Why there is no wireless switch?

Did the Byzantines ever attempt to move their capital to Rome?

Dissuading my girlfriend from a scam

Was the lunar landing site always in the same plane as the CM's orbit?

My Friend James

Temporarily simulate being offline programmatically

How can electricity be positive when electrons are negative?

Where on Earth is it easiest to survive in the wilderness?

How can I hint that my character isn't real?

Why did Boris Johnson call for new elections?

Are there mathematical concepts that exist in the fourth dimension, but not in the third dimension?

Types of tablet... a tablet secretion

French equivalent of "my cup of tea"

What are some countries where you can be imprisoned for reading or owning a Bible?



proxyquire not stubbing static methods - nodejs


How do I test a private function or a class that has private methods, fields or inner classes?What's the difference between faking, mocking, and stubbing?How to mock void methods with MockitoHow can I update NodeJS and NPM to the next versions?Stubbing with proxyquireUsing proxyquire to stub require in 3rd party modules dependencyBabel unexpected token import when running mocha testsproxyquire not stubbing method callstubbing a function in a proxyquired objectProxyquire: Cannot Stub fs.readFileSync






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















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 code:



import ValidationHelper from '../validations/common';
import BeneficiaryHelper from '../validations/beneficiary';
const lib = nbind.init<typeof LibTypes>(__dirname + '/../../').lib;



class beneficiaryaddv2

utilities: any = ;

constructor()
this.utilities = new lib.Utilities();



parse(req: any, res: any, message: [k: string]: any )

//..more code

ValidationHelper.checkMandatory(req.body.beneficiaryType, 'beneficiaryType');
ValidationHelper.checkMandatory(req.body.customerId, 'customerId');
BeneficiaryHelper.checkBeneficiaryType(req.body.beneficiaryType);

message.RESERVED1 = req.body.city;
//..more code




export beneficiaryaddv2


code for unit test of this file:



 class BeneficiaryHelper 
static checkBeneficiaryType(beneficiaryType: string) return;


class ValidationHelper
static checkMandatory(stringValue: string, parameterName: string, errorMessage: string = '') return;



describe('unit test for beneficiary add parse', () =>

let utilBase;
let utilGenerateRRNMock;
let utilGenerateSTANMock;

let target = common.proxyquire('../../APIServer/controller/beneficiaryaddv2',
'nbind': common.nbindStub,
'../../local_modules/logger': common.LoggerMock,
'../validations/common': ValidationHelper,
'../../local_modules/dbconnmgr': common.DbConnMgrMock,
'../validations/beneficiary': BeneficiaryHelper,
'@noCalThrough': true
);

//...

);









share|improve this question


























  • How do you instantiate your class under test, beneficiaryaddv2?

    – Christian
    Mar 28 at 10:47











  • i donot need to instantiate my class. its a static method for class ValidationHelper. have used import ValidationHelper from '../validations/common';

    – Sana.91
    Mar 28 at 11:14


















0















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 code:



import ValidationHelper from '../validations/common';
import BeneficiaryHelper from '../validations/beneficiary';
const lib = nbind.init<typeof LibTypes>(__dirname + '/../../').lib;



class beneficiaryaddv2

utilities: any = ;

constructor()
this.utilities = new lib.Utilities();



parse(req: any, res: any, message: [k: string]: any )

//..more code

ValidationHelper.checkMandatory(req.body.beneficiaryType, 'beneficiaryType');
ValidationHelper.checkMandatory(req.body.customerId, 'customerId');
BeneficiaryHelper.checkBeneficiaryType(req.body.beneficiaryType);

message.RESERVED1 = req.body.city;
//..more code




export beneficiaryaddv2


code for unit test of this file:



 class BeneficiaryHelper 
static checkBeneficiaryType(beneficiaryType: string) return;


class ValidationHelper
static checkMandatory(stringValue: string, parameterName: string, errorMessage: string = '') return;



describe('unit test for beneficiary add parse', () =>

let utilBase;
let utilGenerateRRNMock;
let utilGenerateSTANMock;

let target = common.proxyquire('../../APIServer/controller/beneficiaryaddv2',
'nbind': common.nbindStub,
'../../local_modules/logger': common.LoggerMock,
'../validations/common': ValidationHelper,
'../../local_modules/dbconnmgr': common.DbConnMgrMock,
'../validations/beneficiary': BeneficiaryHelper,
'@noCalThrough': true
);

//...

);









share|improve this question


























  • How do you instantiate your class under test, beneficiaryaddv2?

    – Christian
    Mar 28 at 10:47











  • i donot need to instantiate my class. its a static method for class ValidationHelper. have used import ValidationHelper from '../validations/common';

    – Sana.91
    Mar 28 at 11:14














0












0








0








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 code:



import ValidationHelper from '../validations/common';
import BeneficiaryHelper from '../validations/beneficiary';
const lib = nbind.init<typeof LibTypes>(__dirname + '/../../').lib;



class beneficiaryaddv2

utilities: any = ;

constructor()
this.utilities = new lib.Utilities();



parse(req: any, res: any, message: [k: string]: any )

//..more code

ValidationHelper.checkMandatory(req.body.beneficiaryType, 'beneficiaryType');
ValidationHelper.checkMandatory(req.body.customerId, 'customerId');
BeneficiaryHelper.checkBeneficiaryType(req.body.beneficiaryType);

message.RESERVED1 = req.body.city;
//..more code




export beneficiaryaddv2


code for unit test of this file:



 class BeneficiaryHelper 
static checkBeneficiaryType(beneficiaryType: string) return;


class ValidationHelper
static checkMandatory(stringValue: string, parameterName: string, errorMessage: string = '') return;



describe('unit test for beneficiary add parse', () =>

let utilBase;
let utilGenerateRRNMock;
let utilGenerateSTANMock;

let target = common.proxyquire('../../APIServer/controller/beneficiaryaddv2',
'nbind': common.nbindStub,
'../../local_modules/logger': common.LoggerMock,
'../validations/common': ValidationHelper,
'../../local_modules/dbconnmgr': common.DbConnMgrMock,
'../validations/beneficiary': BeneficiaryHelper,
'@noCalThrough': true
);

//...

);









share|improve this question
















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 code:



import ValidationHelper from '../validations/common';
import BeneficiaryHelper from '../validations/beneficiary';
const lib = nbind.init<typeof LibTypes>(__dirname + '/../../').lib;



class beneficiaryaddv2

utilities: any = ;

constructor()
this.utilities = new lib.Utilities();



parse(req: any, res: any, message: [k: string]: any )

//..more code

ValidationHelper.checkMandatory(req.body.beneficiaryType, 'beneficiaryType');
ValidationHelper.checkMandatory(req.body.customerId, 'customerId');
BeneficiaryHelper.checkBeneficiaryType(req.body.beneficiaryType);

message.RESERVED1 = req.body.city;
//..more code




export beneficiaryaddv2


code for unit test of this file:



 class BeneficiaryHelper 
static checkBeneficiaryType(beneficiaryType: string) return;


class ValidationHelper
static checkMandatory(stringValue: string, parameterName: string, errorMessage: string = '') return;



describe('unit test for beneficiary add parse', () =>

let utilBase;
let utilGenerateRRNMock;
let utilGenerateSTANMock;

let target = common.proxyquire('../../APIServer/controller/beneficiaryaddv2',
'nbind': common.nbindStub,
'../../local_modules/logger': common.LoggerMock,
'../validations/common': ValidationHelper,
'../../local_modules/dbconnmgr': common.DbConnMgrMock,
'../validations/beneficiary': BeneficiaryHelper,
'@noCalThrough': true
);

//...

);






node.js typescript unit-testing mocha proxyquire






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 6:57







Sana.91

















asked Mar 28 at 5:11









Sana.91Sana.91

4742 gold badges14 silver badges37 bronze badges




4742 gold badges14 silver badges37 bronze badges















  • How do you instantiate your class under test, beneficiaryaddv2?

    – Christian
    Mar 28 at 10:47











  • i donot need to instantiate my class. its a static method for class ValidationHelper. have used import ValidationHelper from '../validations/common';

    – Sana.91
    Mar 28 at 11:14


















  • How do you instantiate your class under test, beneficiaryaddv2?

    – Christian
    Mar 28 at 10:47











  • i donot need to instantiate my class. its a static method for class ValidationHelper. have used import ValidationHelper from '../validations/common';

    – Sana.91
    Mar 28 at 11:14

















How do you instantiate your class under test, beneficiaryaddv2?

– Christian
Mar 28 at 10:47





How do you instantiate your class under test, beneficiaryaddv2?

– Christian
Mar 28 at 10:47













i donot need to instantiate my class. its a static method for class ValidationHelper. have used import ValidationHelper from '../validations/common';

– Sana.91
Mar 28 at 11:14






i donot need to instantiate my class. its a static method for class ValidationHelper. have used import ValidationHelper from '../validations/common';

– Sana.91
Mar 28 at 11:14













1 Answer
1






active

oldest

votes


















1
















Hope this works (y)!!!



let ValidationHelperMock = 
ValidationHelper: class
static checkMandatory(stringValue, parameterName, errorMessage) ;

;

let BeneficiaryHelperMock =
BeneficiaryHelper: class
static checkBeneficiaryType(beneficiaryType) ;

;

describe('unit test for beneficiary add parse', () =>

let utilBase;
let utilGenerateRRNMock;
let utilGenerateSTANMock;

let target = common.proxyquire('../../APIServer/controller/beneficiaryaddv2',
'nbind': common.nbindStub,
'../../local_modules/logger': common.LoggerMock,
'../validations/common': ValidationHelperMock, //check these paths to exact from the test file
'../../local_modules/dbconnmgr': common.DbConnMgrMock,
'../validations/beneficiary': BeneficiaryHelperMock, //check these paths to exact from the test file
'@noCalThrough': true
);

//...

);





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390569%2fproxyquire-not-stubbing-static-methods-nodejs%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1
















    Hope this works (y)!!!



    let ValidationHelperMock = 
    ValidationHelper: class
    static checkMandatory(stringValue, parameterName, errorMessage) ;

    ;

    let BeneficiaryHelperMock =
    BeneficiaryHelper: class
    static checkBeneficiaryType(beneficiaryType) ;

    ;

    describe('unit test for beneficiary add parse', () =>

    let utilBase;
    let utilGenerateRRNMock;
    let utilGenerateSTANMock;

    let target = common.proxyquire('../../APIServer/controller/beneficiaryaddv2',
    'nbind': common.nbindStub,
    '../../local_modules/logger': common.LoggerMock,
    '../validations/common': ValidationHelperMock, //check these paths to exact from the test file
    '../../local_modules/dbconnmgr': common.DbConnMgrMock,
    '../validations/beneficiary': BeneficiaryHelperMock, //check these paths to exact from the test file
    '@noCalThrough': true
    );

    //...

    );





    share|improve this answer





























      1
















      Hope this works (y)!!!



      let ValidationHelperMock = 
      ValidationHelper: class
      static checkMandatory(stringValue, parameterName, errorMessage) ;

      ;

      let BeneficiaryHelperMock =
      BeneficiaryHelper: class
      static checkBeneficiaryType(beneficiaryType) ;

      ;

      describe('unit test for beneficiary add parse', () =>

      let utilBase;
      let utilGenerateRRNMock;
      let utilGenerateSTANMock;

      let target = common.proxyquire('../../APIServer/controller/beneficiaryaddv2',
      'nbind': common.nbindStub,
      '../../local_modules/logger': common.LoggerMock,
      '../validations/common': ValidationHelperMock, //check these paths to exact from the test file
      '../../local_modules/dbconnmgr': common.DbConnMgrMock,
      '../validations/beneficiary': BeneficiaryHelperMock, //check these paths to exact from the test file
      '@noCalThrough': true
      );

      //...

      );





      share|improve this answer



























        1














        1










        1









        Hope this works (y)!!!



        let ValidationHelperMock = 
        ValidationHelper: class
        static checkMandatory(stringValue, parameterName, errorMessage) ;

        ;

        let BeneficiaryHelperMock =
        BeneficiaryHelper: class
        static checkBeneficiaryType(beneficiaryType) ;

        ;

        describe('unit test for beneficiary add parse', () =>

        let utilBase;
        let utilGenerateRRNMock;
        let utilGenerateSTANMock;

        let target = common.proxyquire('../../APIServer/controller/beneficiaryaddv2',
        'nbind': common.nbindStub,
        '../../local_modules/logger': common.LoggerMock,
        '../validations/common': ValidationHelperMock, //check these paths to exact from the test file
        '../../local_modules/dbconnmgr': common.DbConnMgrMock,
        '../validations/beneficiary': BeneficiaryHelperMock, //check these paths to exact from the test file
        '@noCalThrough': true
        );

        //...

        );





        share|improve this answer













        Hope this works (y)!!!



        let ValidationHelperMock = 
        ValidationHelper: class
        static checkMandatory(stringValue, parameterName, errorMessage) ;

        ;

        let BeneficiaryHelperMock =
        BeneficiaryHelper: class
        static checkBeneficiaryType(beneficiaryType) ;

        ;

        describe('unit test for beneficiary add parse', () =>

        let utilBase;
        let utilGenerateRRNMock;
        let utilGenerateSTANMock;

        let target = common.proxyquire('../../APIServer/controller/beneficiaryaddv2',
        'nbind': common.nbindStub,
        '../../local_modules/logger': common.LoggerMock,
        '../validations/common': ValidationHelperMock, //check these paths to exact from the test file
        '../../local_modules/dbconnmgr': common.DbConnMgrMock,
        '../validations/beneficiary': BeneficiaryHelperMock, //check these paths to exact from the test file
        '@noCalThrough': true
        );

        //...

        );






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 12:42









        Ameer AbbasAmeer Abbas

        262 bronze badges




        262 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390569%2fproxyquire-not-stubbing-static-methods-nodejs%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript