Let's say we want to test that a specific function is called by another function using Sinon.
fancyModule.js
export const fancyFunc = () => {
console.log('fancyFunc')
}
export default const fancyDefault = () => {
console.log('fancyDefault')
fancyFunc()
}
fancyModule.test.js
import sinon from 'sinon'
import fancyDefault, { fancyFunc } from '../fancyModule'
describe('fancyModule', () => {
it('calls fancyFunc', () => {
const spy = sinon.spy(fancyFunc)
fancyDefault()
expect(spy.called).to.be.true
})
})
When I run this test the actual value is always false. Also, the original function fancyFunc()
gets invoked (outputs fancyFunc) instead of being mocked.