I have the following code. Sinon failed to mock doSomething() and printing actual string instead of 'hello'
//file.js
import { doSomething } from 'my-npm-package';
module.exports = () => doSomething();
This is the test file:
//file.spec.js
import sinon from 'sinon';
import { expect } from 'chai';
import * as apis from 'my-npm-package';
import someFunction from '../file';
describe('TEST', () => {
let stub;
beforeEach(() => {
stub = sinon.stub(apis, 'doSomething').returns('hello');
});
afterEach(() => {
stub.restore();
});
it('test', async () => {
someFunction();
expect(stub.calledOnce).to.equal(true);
});
});