Mock objects with ease
npm install hoax.js --save
const hoax = require('hoax.js');
const mock = hoax(console, 'log');
// Do not actually log to console
console.log('unicorn');
console.log('rainbow');
console.log('magic');
// Get calls to the mocked function
mock.calls;
//=> [
//=> ['unicorn'],
//=> ['rainbow'],
//=> ['magic'],
//=> ]
// Reset when done
mock.reset();
// Does log to console
console.log('This will be logged');
// You may also provide a function to return whatever you want
const mock = hoax(process, 'cwd', () => '/fake/path');
process.cwd();
//=> /fake/path
mock.reset();
process.cwd();
//=> /ecrmnn/hoax.js
MIT © Daniel Eckermann