mercredi 5 août 2020

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() {
   business logic
    const result = c.getApiResult();
    business logic on result
    return final result

}

Module C

function getApiResult() {
       return api.get(/test/1);
   }

I've written a test for module A but am running into an issue with stubbing dependencies.I just want to stub c.getApiResult() and not b.getInfo or b.getDetailInfo(). I've tried selectively stubbing using proxyquire but am having issues. Any help?

Aucun commentaire:

Enregistrer un commentaire