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(file,data,_cb) }); writeImageStub("abc.txt","Hello world",(err, data)=>{ console.log(err,data); }) On Sat, Nov 2, 2019 at 3:37 AM Lukas Wilkeer <lukas...@gmail.com> wrote: > 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) => { > expect(file).to.be.a('string') > expect(getFileExtension(data)).to.equal('jpg') > expect(new Buffer.alloc(data)).to.be.a('object') > > return '/static/images/image.jpg' > })) > > *Reference error*: file is not defined. > > How to do this, what causing this and exist other method? > > > *PS:* > Spying the method causes the write operation to be executed, on this case > i have to delete the files written, but how to get the filename as the > format is *filename.Date.now.extension*. Don't exist a way to store as a > global variable to do this. > > -- > Job board: http://jobs.nodejs.org/ > New group rules: > https://gist.github.com/othiym23/9886289#file-moderation-policy-md > Old group rules: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to nodejs+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/3d26db31-2c2c-4c3b-8055-7c8f54628bf6%40googlegroups.com > <https://groups.google.com/d/msgid/nodejs/3d26db31-2c2c-4c3b-8055-7c8f54628bf6%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Regards, Amresh Yadav -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender immediately. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAPVEQmePxLBJhBr%2ByAb0xz%2BFFDKATSMFW9Dy26nkFe7-jvitWw%40mail.gmail.com.