npm.io
1.0.8 • Published 6 years ago

console-mock2

Licence
MIT
Version
1.0.8
Deps
0
Size
5 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

console-mock2

NPM version Linux macOS Windows compatible

Build status Coverage status Dependency status Renovate enabled

Open in Gitpod

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:

MIT License

Keywords