🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

console-test-helpers

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-test-helpers

Test helpers for building console UIs

0.3.0
Source
npm
Version published
Weekly downloads
71
-51.03%
Maintainers
1
Weekly downloads
 
Created
Source

console-test-helpers

When building CLIs that output to the console, it's useful to be able to record and validate the console output for subsequent verification. Doing so requires a few useful helpers:

  • A console replacement to record the actual console output
  • A fixture mechanism to store the expected output

console-test-helpers provides the above.

Installation

yarn add console-test-helpers --dev

# or

npm install console-test-helpers --save-dev

Usage

console-test-helpers replaces the real console with a fake, which stores the output in addition to acting as a proxy for all console calls. This means the console will behave the same, but will gather output for later validation. Validation can be performed using fixtures that can be asserted against.

Below is an example using qunit-console-test-helpers, the sister package to console-test-helpers.

import { module, test } from 'qunit';
import { setupMockConsole } from 'qunit-console-test-helpers';

// ...
module('With mocked console', function(hooks) {
  setupMockConsole(hooks, { fixturePath: './tests/fixtures' });

  test('Something that mocks the console', function(assert) {
    somethingThatUsesConsole();

    assert.console().matches('fixture-name');
  });
});

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

FAQs

Package last updated on 07 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts