I wish to stub a function used in the file I'm currently testing. This function is required with a destructuring like this:
const { theFunctionIWant } = require('path/to/module')
When testing, the stub is never called, and the real function proceed to be called.
But when I require it 'normally' (i.e: without destructuring)
const myModule = require('path/to/module')
then the stub is correctly used and everything works fine
I sense that it's because of how the destructuring works and the fact that sinon
stub the object property and not the function directly. Anyhow if you can provide me some insights I will be grateful !
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…