# console-test-helpers

> Test helpers for building console UIs

Latest version **0.3.3** (published 2020-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install console-test-helpers
pnpm add console-test-helpers
yarn add console-test-helpers
bun add console-test-helpers
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2020-01-30 |
| First published | 2019-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 26.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | scalvert |
| Maintainers | scalvert |

## Links

- npm: https://www.npmjs.com/package/console-test-helpers
- Repository: https://github.com/scalvert/console-test-helpers
- Homepage: https://github.com/scalvert/console-test-helpers#readme
- Issues: https://github.com/scalvert/console-test-helpers/issues
- npm.io page: https://npm.io/package/console-test-helpers

## Dependencies (1)

- [recursive-readdir-sync](https://npm.io/package/recursive-readdir-sync.md) ^1.0.6

## Recent versions

- 0.3.3 (latest) — 2020-01-30
- 0.3.2 — 2020-01-29
- 0.3.1 — 2020-01-17
- 0.3.0 — 2020-01-07
- 0.2.0 — 2020-01-07
- 0.1.0 — 2019-12-29

## README

# 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
console replacement to record the _actual_ console output. `console-test-helpers` provides this.

## Installation

```bash
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 of its usage in `qunit-console-test-helpers`, this sister package to `console-test-helpers`.

```ts
export function setupMockConsole(hooks: NestedHooks, options: MockConsoleOptions) {
  let resetConsole: () => void;

  setupFixtures(options); // from the qunit-fixtures package

  hooks.beforeEach(function() {
    ({ resetConsole, consoleState } = mockConsole(options));
  });

  hooks.afterEach(function() {
    resetConsole();
  });
}
```

And below is how it's used within tests.

```js
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](CONTRIBUTING.md) guide for details.

## License

This project is licensed under the [MIT License](LICENSE.md).

---
_Source: https://npm.io/package/console-test-helpers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
