console-mock2
Mocks console output for Node.js unit tests by wrapping a block and returning the output as an array.
Install
# NPM
$ npm install console-mock2
# Yarn
$ yarn add console-mock2
Usage
const consoleMock = require('console-mock2');
function someVerboseFunction(param) {
console.log('foo');
console.log('bar');
return 5;
}
var output = [];
var result = consoleMock(() => someVerboseFunction(param), output);
// output = ['foo']
// result = 5
consoleMock(() => {
someVerboseFunction(param);
...
});
consoleMock(new Promise((resolve, reject) => {
setTimeout(() => {
console.log('foo');
resolve();
});
});
License
Unless stated otherwise all works are:
Copyright © Sebastian Landwehr info@dword-design.de
and licensed under: