hoax.js

Mock objects with ease

Usage no npm install needed!

<script type="module">
  import hoaxJs from 'https://cdn.skypack.dev/hoax.js';
</script>

README

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