spyfs
spyfs copied to clipboard
fs.closeSync error
javascript const spyfs = require( 'spyfs' ); const sfs = spyfs.spy( fs, action => { console.log( action ); } ); const fd = sfs.openSync( __filename, 'r' ); sfs.closeSync( fd ); // error, return undefined
const spyfs = require( 'spyfs' );
const sfs = spyfs.spy( fs, action => { console.log( action ); } );
const fd = sfs.openSync( __filename, 'r' );
sfs.closeSync( fd ); // error, return undefined
I can reproduce the same problem with any sync method that does not return a value like fs.writeFileSync(). The bug is in Spy's #returnOrThrow function. When I change
function returnOrThrow() {
if (typeof result !== 'undefined') {
return result;
} else {
throw error;
}
}
to more meaningful
function returnOrThrow() {
if(error) {
throw error;
} else {
return result;
}
}
everything work fine.