https://github.com/sporeball/tentamen
a tiny JavaScript testing framework
https://github.com/sporeball/tentamen
node testing
Last synced: 8 months ago
JSON representation
a tiny JavaScript testing framework
- Host: GitHub
- URL: https://github.com/sporeball/tentamen
- Owner: sporeball
- License: mit
- Created: 2021-07-19T21:01:06.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T06:56:55.000Z (over 3 years ago)
- Last Synced: 2025-02-10T03:09:01.250Z (over 1 year ago)
- Topics: node, testing
- Language: JavaScript
- Homepage:
- Size: 37.1 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tentamen
**tentamen** is a tiny (less than 50 source lines of code) JavaScript testing framework, just perfect for making sure that a function gives the right return values.\
it uses deep equality, so you can easily test against things like arrays, objects, [and even error instances.](#on-tests-and-errors)
### install
```
npm i --save tentamen
```
### usage
```js
import Tentamen from 'tentamen';
let tentamen = new Tentamen({
fn: str => str.startsWith('a')
});
tentamen.suite('truthy cases');
tentamen.add('absolutely', 'absolutely', true);
tentamen.add('acknowledge', 'acknowledge', true);
tentamen.suite('falsy cases');
tentamen.add('tentamen', 'tentamen', false);
tentamen.add('percentage', 'percentage', false);
tentamen.done();
```
```
$ node test.js
truthy cases
o absolutely
o acknowledge
falsy cases
o tentamen
o percentage
4 of 4 tests passing
```
## API
### new Tentamen(obj)
#### obj
type: `object`
##### fn
type: `function`
the function to run tests on.
##### before
type: `function`
function to call before each test. good for pre-conditions.
##### after
type: `function`
function to call after each test. good for cleanup.
### tentamen.suite(title, fn?)
start a new group of tests.
#### title
type: `string`
the suite title.
#### fn
type: `function`
a new function to replace the current value of `this.fn` with.
### tentamen.add(title, input, expected)
run a new test.
#### title
type: `string`
the test title.
#### input
type: `any`
the input to test with.\
[`tentamen.input`](#tentameninput) will be equal to this value.
#### expected
type: `any`
the expected output of the test.
### tentamen.done()
finish testing, and output the number of passing tests.
### tentamen.input
the input to the test currently being run.
## more information
### on tests and errors
normally, if the function being tested throws an error, tentamen will simply fail the test and show it to you — but what if you want to test *for* an error, to make sure that your code is throwing the right thing at the right time?
in that case, you can add a test whose `expected` value is an error instance:
```js
tentamen.suite('error');
// arrays don't have a startsWith method!
tentamen.add('should fail', [], new TypeError);
```
```
error
o should fail
(TypeError)
```
this works with custom error classes, too.
### license
MIT