Skip to content

ecrmnn/hoax.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hoax.js

Mock objects with ease

travis npm version npm downloads npm license prs Welcome eslint

Installation

npm install hoax.js --save

Usage

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

License

MIT © Daniel Eckermann