Geoff Doty f38a7fe295 | ||
---|---|---|
dist | ||
src | ||
test | ||
.gitignore | ||
.jshintrc | ||
CONTRIBUTING.md | ||
LICENSE | ||
README.md | ||
gulpfile.js | ||
package-lock.json | ||
package.json |
README.md
Test.it
A minimalistic testing library
Test.it is a small testing library for people that want to live in code, not in tests. No over engineering here. Inspired by the simplicity of libraries like Tape,but the implementation ideas of things like Expect and TinyTest
This is probally not a cure-all testing solution, if you want something more robust checkout Jasmine, Tape or Mocha -- this is to...
Test small things, with small things
Features
- Works in the Browser
- Works with CommonJS (aka NodeJS)
- Barely over a 100 lines
- Single File
- No Dependicies
- 2kb footprint (before gzip)
- Extend with custom reporters
- Has an Expect-like style BDD assertions
No Bloat Here!
Usage
By default, you can run your tests like
test.it({
'my passing test': function() {
test.expects().to.pass();
},
'my failing test': function() {
test.expects().to.fail('just wanted to fail fast');
}
}).run();
NOTE:
run()
can be called elsewhere, see tests/
by default, your test results are logged to the console
+OK my passing test
-ERR my failing test
---
Error: just wanted to fail fast
...error stack...
---
# tests 2 pass 1 fail 1
A +OK
will proceed test lines that pass and a -ERR
for those that fail, An error stack is included by default after the failing test wrapped in ---
. You can suppress outputing the error stack by passing false
as an argument to run()
, ie run(false)
.
You can, also, write your own custom test runner...
Custom Test Runners
test.it
.run()
method provides an optional next
function parameter that passes the results as an object
for you to process however you like.
For Example...
For Fans of TinyTest
test.it({
'my passing test': function() {
test.pass();
}
}, function(results) {
if (window.document && document.body) {
document.body.style.backgroundColor = (
results.fail.length ? '#ff9999' : '#99ff99'
);
}
});
If using the optional next
param will return results as JSON
{
"pass": ["list of passed tests", "..."],
"fail": ["list of errored tests", "..."],
}
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.
REMEMBER: you can bypass error output too
A sample test runner is provided for both HTML and NODE in the test/
directory; run.html
and run.js
respectfully.
Methods
To stay minimal, test.it
only has 3 core functions:
it
to capture your testsrun
to execute yours tests- and
expects
to write your assertions
While you can use your own assertion library, the included expects
provides the following methods for writing your tests:
Methods | Description |
---|---|
.expects(tests).to.exist() |
truthy evalution .exist or .be.ok() |
.expects().to.pass() |
pass test |
.expects().to.fail(message) |
fails test with message |
.expects(this).to.equal(that) |
strictly equal evaluation using === |
.expects(this).to.be.like(that) |
loose evaluation using == |
.expects(123).to.be.a('number') |
check typeof value (.a() or .an() ) |
NOTE: wish
eval
was not so evil,assert(expression, message)
would be ideal
if you want to shorten test typing try
let expect = test.expects;
putting that above your tests will allow you to write like
test.it({
"my test should work": function() {
expect().to.pass();
}
});
TODO
- write
not
expects, ieexpects(this).to.not.equal(this)
- provide sample test runner for CI environments
Support
Please open an issue for support.
Contributing
Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines, they're minimalistic;)