@rgrannell/testing v9.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
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
- givenAll
- always
- run
- theory.run
- testing.theory
- failed
- passed
- errored
- failed
- passed
- errored
- percentages
- tap
- hypothesis
API Documentation
given
Parameters
state
hypothesis
Object a hypothesis object.
Returns Object an object with several methods:- given()
- givenAll()
- run()
givenAll
Parameters
state
hypotheses
Object an object of name - hypothesis mappings.
Returns Object an object with several methods:- given()
- givenAll()
- run()
always
Parameters
state
condition
function a function returning true or false
Returns Object 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 returns an object with several methods:- .run()
- .given()
- .givenAll()
failed
Validate & construct failed hypotheses results
Parameters
$0
Object$0.condition
$0.testCase
$0.hypothesis
Returns Object
passed
Validate & construct passed hypotheses results
Parameters
$0
Object$0.condition
$0.testCase
$0.hypothesis
Returns Object
errored
Validate & construct errored hypotheses results
Parameters
$0
Object$0.condition
$0.testCase
$0.hypothesis
$0.error
Returns Object
Returns Array<HypothesisResult> all test-results
failed
Returns Array<HypothesisResult> all test-results
passed
Returns Array<HypothesisResult> passed test-results
errored
Returns Array<HypothesisResult> error-throwing test-results
percentages
Returns Object 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
Returns undefined
Parameters
generator
GeneratorFunction a function yielding test-cases
Returns Object an object with the following methods:- always()
hypothesis
Parameters
hypothesis
string a description of the hypothesis
Returns Object an object with the method:- cases()
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.
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago