testit/README.md

111 lines
3.3 KiB
Markdown
Raw Normal View History

2018-03-31 22:45:35 +00:00
# Test.it
> A minimalistic testing library
**Test.it** is a small testing library for people that want to live in code, not tests. No over engineering here. Inspired by the simplicity of libraries like [Tape](https://github.com/substack/tape), but the implementation ideas of [TinyTest](https://github.com/joewalnes/jstinytest)
2018-04-02 08:37:02 +00:00
### Features
- Works in the Browser
- Works with CommonJS (aka NodeJS)
- Less than 100 lines
- Single File
2018-04-02 09:21:42 +00:00
- No Dependicies
- 2kb footprint (*before gzip*)
- Extend with custom reporters
2018-04-02 08:37:02 +00:00
**No Bloat Here!**
2018-04-02 09:21:42 +00:00
- [Download Now Available](https://raw.githubusercontent.com/n2geoff/testit/master/src/testit.min.js)
2018-04-02 08:37:02 +00:00
2018-03-31 22:45:35 +00:00
## Usage
By default, you can run your tests like
```js
test.it({
'my passing test': function() {
test.pass();
},
'my failing test': function() {
test.fail('just wanted to fail fast');
}
2018-04-02 08:37:02 +00:00
}).run();
2018-03-31 22:45:35 +00:00
```
2018-04-02 08:37:02 +00:00
> NOTE: `run()` can be called elsewhere, see [tests/](test/runner.html)
2018-03-31 22:45:35 +00:00
2018-04-02 08:37:02 +00:00
`test.it` will return `true` if the tests pass or `false` otherwise. Typical console output:
2018-03-31 22:45:35 +00:00
```
+ my passing test
- my failing test
- - Error: just wanted to fail fast
...error stack...
# tests 1 pass 1 fail 0
```
A `+` will proceed test lines that pass and a `-` for those that fail, the trace back `file:line` is included after the failing test proceeded by `- -`
### Optional Next
2018-04-02 08:37:02 +00:00
`test.it` `.run()` method provides an optional `next` function parameter that will return the results as an `object` for you to process *however* you like
For Example...
2018-03-31 22:45:35 +00:00
**For Fans of [TinyTest](https://github.com/joewalnes/jstinytest)**
```js
test.it({
'my passing test': function() {
test.pass();
}
}, function(results) {
if (window.document && document.body) {
document.body.style.backgroundColor = (
results.fail.length ? '#ff9999' : '#99ff99'
);
}
});
```
### Sample Results Object
```json
{
2018-04-02 09:21:42 +00:00
"pass": ["list of passed tests", "..."],
"fail": ["list of errored tests", "..."],
2018-03-31 22:45:35 +00:00
}
```
2018-04-02 08:37:02 +00:00
From this object you can easily find the number of tests ran `pass.length`, number of failed tests `fail.length` or the total test count by adding the two. Simple.
2018-03-31 22:45:35 +00:00
## Methods
2018-04-02 08:37:02 +00:00
To stay minimal, `test.it` only provides 7 methods, 5 for assertion, 1 to capture tests
and 1 to run tests
2018-03-31 22:45:35 +00:00
2018-04-02 08:37:02 +00:00
| Methods | Description |
| ------------------------------- | --------------------------------------- |
| `test.it(tests)` | captures test object |
| `test.it(tests).run(next)` | runs tests w/ optional processing |
| `test.pass()` | pass test |
| `test.fail(message)` | fails test with message |
| `test.exists(value)` | check if value exists |
| `test.assert(expected, actual)` | evaluates results using `==` |
| `test.equals(expected, actual)` | evaluates results using `===` |
2018-03-31 22:45:35 +00:00
> NOTE: wish `eval` was not so evil, `assert(expression, message)` would be ideal
2018-04-02 08:37:02 +00:00
## Support
Please open [an issue](https://github.com/n2geoff/testit/issues/new) for support.
## Contributing
2018-04-02 10:24:55 +00:00
Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the [guidelines](CONTRIBUTING.md), there minimalistic;)
2018-04-02 08:37:02 +00:00
2018-03-31 22:45:35 +00:00
## License
2018-04-02 10:24:55 +00:00
[MIT](LICENSE).
2018-03-31 22:45:35 +00:00