Though there is a same question here but I could not find answer to my problem so here goes my question:
I am testing my node js app using mocha and chai. I am usin
I was also hitting this using the before() and after() hooks of Mocha. I was also using the restore() as mentioned everywhere. Single test file ran fine, multiple did not. Finally found about Mocha root-level-hooks: I did not have my before() and after() inside my own describe(). So it finds all files with before() at the root-level and executes those before starting any tests.
So make sure you have a similar pattern:
describe('my own describe', () => {
before(() => {
// setup stub code here
sinon.stub(myObj, 'myFunc').callsFake(() => {
return 'bla';
});
});
after(() => {
myObj.myFunc.restore();
});
it('Do some testing now', () => {
expect(myObj.myFunc()).to.be.equal('bla');
});
});