Skip to content

Instantly share code, notes, and snippets.

@devarajchidambaram
devarajchidambaram / stubfs.js
Created September 7, 2018 07:28
How to stub fs.readFile functions
const fs = require('fs')
function readFile (filename) {
if (fs.existsSync(filename)) {
return fs.readFileSync(filename, 'utf8')
}
throw new Error('Cannot find file ' + filename)
}
describe('mocking individual fs sync methods', () => {