Given that I have two ES6 classes.
This is class A:
import B from 'B';
class A {
someFunction(){
var dependency = new B();
dependency.doSomething();
}
}
And class B:
class B{
doSomething(){
// does something
}
}
I am unit testing using mocha (with babel for ES6), chai and sinon, which works really great. But how can I provide a mock class for class B when testing class A?
I want to mock the entire class B (or the needed function, doesn't actually matter) so that class A doesn't execute real code but I can provide testing functionality.
This is, what the mocha test looks like for now:
var A = require('path/to/A.js');
describe("Class A", () => {
var InstanceOfA;
beforeEach(() => {
InstanceOfA = new A();
});
it('should call B', () => {
InstanceOfA.someFunction();
// How to test A.someFunction() without relying on B???
});
});