# @rgrannell/testing

> test utilities

Latest version **9.4.0** (published 2020-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rgrannell/testing
pnpm add @rgrannell/testing
yarn add @rgrannell/testing
bun add @rgrannell/testing
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 9.4.0 |
| Published | 2020-07-08 |
| First published | 2018-07-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 22.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | rgrannell |

## Links

- npm: https://www.npmjs.com/package/@rgrannell/testing
- npm.io page: https://npm.io/package/@rgrannell/testing

## Dependencies (4)

- [chai](https://npm.io/package/chai.md) ^4.1.2
- [sinon](https://npm.io/package/sinon.md) ^6.1.4
- [yamljs](https://npm.io/package/yamljs.md) ^0.3.0
- [@rgrannell/chain](https://npm.io/package/@rgrannell/chain.md) ^9.4.0

## Recent versions

- 9.4.0 (latest) — 2020-07-08
- 8.1.0-alpha.49d6f21a (canary) — 2018-08-02
- 9.3.0 — 2020-07-08
- 9.2.0 — 2020-07-07
- 9.1.0 — 2019-10-01
- 9.0.0 — 2019-09-01
- 8.4.0 — 2019-08-11
- 8.2.0 — 2018-08-06
- 8.1.0 — 2018-08-04
- 8.1.0-alpha.99dad58c — 2018-07-27
- 8.1.0-alpha.278140ed — 2018-07-26

## README

# testing (v9.3.0)

## Stability

> 0 - Experimental

test utilities


## Overview

`testing` is a simple test-runner that allows you to describe tests in terms of:

- expectations & predicates
- hypotheses
- theories composed of hypotheses

this framework is a pure-JS test-runner, as opposed to `mocha` or `ava` which requires you to use external binaries.


## Usage

```js
const {
  hypothesis,
  theory
} = require('@rgrannell/testing')

const hypotheses = {}

hypotheses.add = hypothesis('adding zero to a number returns that number')
  .cases(function * () {
    yield [1]
    yield [2]
    yield [3]
  })
  .always(num => {
    return num + 0 === num
  })

theory({ description: 'Establish basic laws of addition are satisfied over numeric inputs' })
  .givenAll(hypotheses)
```

## Table of Contents

- [given](#given)
  * [Parameters](#parameters)
- [givenAll](#givenall)
  * [Parameters](#parameters-1)
- [always](#always)
  * [Parameters](#parameters-2)
- [run](#run)
  * [Parameters](#parameters-3)
- [theory.run](#theoryrun)
- [testing.theory](#testingtheory)
- [failed](#failed)
  * [Parameters](#parameters-4)
- [passed](#passed)
  * [Parameters](#parameters-5)
- [errored](#errored)
  * [Parameters](#parameters-6)
- [failed](#failed-1)
- [passed](#passed-1)
- [errored](#errored-1)
- [percentages](#percentages)
- [tap](#tap)
  * [Parameters](#parameters-7)
  * [Parameters](#parameters-8)
- [hypothesis](#hypothesis)
  * [Parameters](#parameters-9)

## API Documentation

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## given

### Parameters

-   `state`  
-   `hypothesis` **[Object][1]** a hypothesis object.

Returns **[Object][1]** an object with several methods:-   given()
-   givenAll()
-   run()

## givenAll

### Parameters

-   `state`  
-   `hypotheses` **[Object][1]** an object of name - hypothesis mappings.

Returns **[Object][1]** an object with several methods:-   given()
-   givenAll()
-   run()

## always

### Parameters

-   `state`  
-   `condition` **[function][2]** a function returning true or false

Returns **[Object][1]** an object with the following methods:-   always()
-   run()

## run

### Parameters

-   `state`  

Returns **HypothesisResultSet** a description of the test-execution

## theory.run

Returns **theoryResultSet** returns a data-model

## testing.theory

Returns **[Object][1]** returns an object with several methods:-   .run()
-   .given()
-   .givenAll()

## failed

Validate & construct failed hypotheses results

### Parameters

-   `$0` **[Object][1]** 
    -   `$0.condition`  
    -   `$0.testCase`  
    -   `$0.hypothesis`  

Returns **[Object][1]** 

## passed

Validate & construct passed hypotheses results

### Parameters

-   `$0` **[Object][1]** 
    -   `$0.condition`  
    -   `$0.testCase`  
    -   `$0.hypothesis`  

Returns **[Object][1]** 

## errored

Validate & construct errored hypotheses results

### Parameters

-   `$0` **[Object][1]** 
    -   `$0.condition`  
    -   `$0.testCase`  
    -   `$0.hypothesis`  
    -   `$0.error`  

Returns **[Object][1]** 

## 

Returns **[Array][3]&lt;HypothesisResult>** all test-results

## failed

Returns **[Array][3]&lt;HypothesisResult>** all test-results

## passed

Returns **[Array][3]&lt;HypothesisResult>** passed test-results

## errored

Returns **[Array][3]&lt;HypothesisResult>** error-throwing test-results

## percentages

Returns **[Object][1]** an object describing the test-results. Contains the fields:-   results  the raw test-results
-   status
-   pct:
    -   failed: the percentage of failed results
    -   passed: the percentage of passed results
    -   errored: the percentage of error-throwing results

## tap

Create a TAP report for a test-run.

### Parameters

-   `results` **[Array][3]&lt;[Object][1]>** An array of test-results
-   `opts` **[Object][1]** Various options

Returns **[undefined][4]** 

## 

### Parameters

-   `generator` **GeneratorFunction** a function yielding test-cases

Returns **[Object][1]** an object with the following methods:-   always()

## hypothesis

### Parameters

-   `hypothesis` **[string][5]** a description of the hypothesis

Returns **[Object][1]** an object with the method:-   cases()

[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function

[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String


## Dependencies

- Node.js >= v10.6.0
- NPM >= v10.6.0

## License

Copyright (c) 2020 Róisín Grannell

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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