npm package: @rgrannell/testing
Description: test utilities
Latest version: 9.4.0


# 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.