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;
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
add a comment |
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
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
add a comment |
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
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
node.js typescript unit-testing mocha proxyquire
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
);
//...
);
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
);
//...
);
add a comment |
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
);
//...
);
add a comment |
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
);
//...
);
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
);
//...
);
answered Mar 28 at 12:42
Ameer AbbasAmeer Abbas
262 bronze badges
262 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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