Mock fs.readdir for testing
I'm trying to mock the function fs.readdir for my tests. At first I've tried to use sinon because this is a very good framework for this, but is hasn't worked. stub(fs, 'readdir').yieldsTo('callback', { error: null, files: ['index.md', 'page1.md', 'page2.md'] }); My second attempt was to mock the function with a self-replaced function. But it also doesn't works. beforeEach(function () { original = fs.readdir; fs.readdir = function (path, callback) { callback(null, ['/content/index.md', '/content/page1.md', '/content/page2.md']); }; }); afterEach(function () { fs.readdir = original; }); Can