Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scalvert/console-test-helpers
Test helpers for building console UIs
https://github.com/scalvert/console-test-helpers
Last synced: about 2 months ago
JSON representation
Test helpers for building console UIs
- Host: GitHub
- URL: https://github.com/scalvert/console-test-helpers
- Owner: scalvert
- Created: 2019-12-23T02:55:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-30T23:18:49.000Z (almost 5 years ago)
- Last Synced: 2024-04-25T18:21:13.836Z (8 months ago)
- Language: TypeScript
- Size: 16.2 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
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
few useful helpers:- A console replacement to record the _actual_ console output
- A fixture mechanism to store the _expected_ output
- An assertion mechanism, whereby you can assert _actual_ output against _expected_ fixtures`console-test-helpers` provides all of the above.
## 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 using `qunit-console-test-helpers`, the sister package to `console-test-helpers`.
```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).