After Stubbing Function Still It Calls The Real Function
I have stubbed the content of file, so I can run through only outer function file.html file.js const fs1 = require('fs');
Solution 1:
You should probably try to stub readFileSync
.
const fs = require('fs');
// ...
sinon.stub(fs, "readFileSync").callsFake ((someArg) => {
return "this is my file content";
});
Besides that, I can spot two issues with your code.
The real
readFileSync
will return aBuffer
if called without a second parameter, not a string like your stub does.The body onload event only exists inside the DOM. The
fs
module is only available in Node.js. If you run your code in a browser, you won't be able to usefs.readFileSync
. If you run it in Node, your HTML file and the onload event won't be useful.
Post a Comment for "After Stubbing Function Still It Calls The Real Function"