How do i mock creating constructor of my parent class in derived class.
here is the example i am testing.
myclass.js
class a {
constructor() {
console.log('i am from class a constructor');
}
foo() {
console.log('i am from class a foo method');
}
}
class b {
constructor() {
console.log('i am from class b constructor');
}
baz() {
let obj = new a();
a.foo();
console.log('i am from class b baz method');
}
}
Here is my unittest, using Sinon.js i am mocking. i am creating unittest for class b -> baz() method. my expectation is to calling baz() method should not call actual class a and it should not print console which is in class a constructor.how can i achive this. sinon.createStubInstance() i used to create object but how to mock constructor?
myclass.test.js
describe('myclass' ()=> {
it('should not call class a constructor', (done) => {
let b_obj = new b()
b_obj.baz();
done()
});
})
Output printing for above code
i am from class a constructor
i am from class a foo method
i am from class b baz method
Expected Output for above code
// should be mocked .. i am from class a constructor
//should be mocked .. i am from class a foo method
i am from class b baz method