Really new to ES6 modules AND automated testing, and I’m stumped!
I’m using mocha/chai/sinon, and unit testing has been going reasonably well, but I’m having trouble figuring out how to isolate “doOtherStuff” in this pattern:
module file
export var doStuff = function doStuff(){
...here be statements...
}
export var doOtherStuff = function doOtherStuff(){
const someValue = doStuff();
...here be more statements...
}
Test file
import * as Things from 'path/to/module'
describe('does it work?', function(){
it('runs as I expect it to', function(){
const result = sinon.stub(Things, 'doStuff');
const theTest = Things.doOtherStuff();
...chai.expect code...
});
});
When the test runs, it errors out on a chunk of code in doStuff (Cannot read property ‘indexOf’ of undefined), which I thought I had stubbed. Is stubbing a dependency from the same module as its caller impossible because of the module’s namespacing or something? I suspect there’s a workaround, but anything I’ve turned up in my googling doesn’t seem to work or doesn’t seem to address this particular pattern. Any help is greatly appreciated!