Mocking a function (startRanging) of a module (beaconsHandler) imported by another module(myModule) (...what a mess)
importproxyquirefrom'proxyquire'// Test case: // - I need to check that myModule calls startRanging (which// is a function that myModule imports from beaconsHandler)// - beaconsHandler may do a lot of things we don't need (like// calling dependecies that are not accessible during our tests)// - ...let's mock startRanging:constmockedStartRanging=()=>nullconstmyModule=proxyquire('../../src/myModule',{'../services/beaconsHandler': {startRanging: mockedStartRanging,'@noCallThru': true// Block dependencies check}})// We can now check that the function is called without messy dependency issues.// In e.g. with Mocha:it('checks for transmission support',()=>{constactual=iterator.next().valueconstexpected=call(mockedStartRanging)expect(actual).to.deep.equal(expected)})