[nodejs] writeFileSync stub causing reference error.

2019-11-01 Thread Lukas Wilkeer
I'm attempt to stub the fs.writeFileSync method, but it's causing a Reference Error. In that case, oeverloading the fs method causes troubes as sinon.restore() doesn't work. *My stub.* const writeImageStub = sinon.stub(fs, 'writeFileSync') .callsFake((file, data, (err) => { expec

[nodejs] Re: Is file closing explicitly needed after fs.readFileSync()?

2019-11-01 Thread Lukas Wilkeer
Em quarta-feira, 23 de outubro de 2019 12:45:02 UTC-3, Peng Yu escreveu: > > I'd like to fs.writeFileSync() to the same file after reading its content > by fs.readFileSync(). It is not clear to me whether fs.closeSync() (or any > other file closing function) is needed between writeFileSync() an

[nodejs] Re: writeFileSync stub causing reference error.

2019-11-01 Thread Corey Cleary
`file` and `data` have no value... so that's why you get the ReferenceError. Understanding why you're trying to stub the filesystem method would help (i.e. - what other code are you trying to test that is causing you to need to stub the fs), but from what I can tell given the context here you c

Re: [nodejs] writeFileSync stub causing reference error.

2019-11-01 Thread Amresh Yadav
Hi Lukas, you can try something like this, const writeImageStub = sinon.stub(fs, 'writeFileSync').callsFake((file, data, _cb)=>{ expect(typeof file).toBe('string'); // expect(getFileExtension(data)).to.equal('jpg') // expect(new Buffer.alloc(data)).to.be.a('object') fs.writeFile(fil