[](http://jsfiddle.net/KeREY/3/)
npm install treejs
I didn't want to do it first, but I liked the vision so much on how it all will come together that after a while I've been dragged in.
- Trust: It's an unittested unit testing framework. You can check out the tests in the test folder, and run them if you will. If you still manage to find a bug in spite all this effort, I'd love to pull your proposed test cases/asserts maybe along with the fixed code itself.
- Functionality: See highlights below.
- Look & Feel:
✓ (cross) marks completed feature.• (dot) means work in progress/partially done._ (empty/underscore) means planned/proposed feature, which awaits sedulous hands. - ✓ Works in the browser
- ✓ Works in AMD environment
- ✓ Works with script tags too
- _ Works with Node.js // shouldn't be hard to implement.
- ✓ Handles async code as never before
- ✓ Assert counting
- ✓ Easily go back and forth between
- ✓ Parallel execution
- ✓ Serial execution
- ✓ Expressive syntax
- ✓ Looks wonderful in the browser
- ✓ Only shows you those asserts that require your attention, and doesn't bother you with the rest. But you can browse them too, if you ever wanted.
- • Looks.. Nice in the console.
- _ You can choose how verbose you want it to be
- ✓ Write as little as you want with the least effort
- ✓ Organize as much as you want into a tree, e.g., for following the structure of your app
- • Many more!
- Google Group / Maining list
- GitHub: @Wizek
- IRC: on Freenode usually in ##javascript and #Node.js under the handle Wizek
- Email: <123.wizek@gmail.com>
``html`1 === 2
When you run this, of course, it's gonna fail, because is false.
Let's grow a branch! (html markup is the same, only writing js part)
`javascript`
tree.branch('Name of the branch', function(tree) {
tree(1).is(2)
tree.done(1)
})
tree.done(0)
Let's do that 2 more times.
`javascript`
tree.branch('Name of the first outer branch', function(tree) {
tree.branch('Name of the one inside the first outer branch', function(tree) {
tree(23).type(number)
tree.done(1)
})
tree.done(0)
})
tree.branch('Name of the second outer one', function(tree) {
tree(1).not.is(2)
tree.done(1)
})
tree.done(0)
Did you notice that you can declare branches within another branch? This helps you to organize your tests into a tree (hence the name Tree.js). It has neat output too!
That should be enough to get you started. For more see "Reference guide" below.
Should you ever need more help, see "Get in touch" section below.
html
`
$3
`html
`
$3
`javascript
var tree = require('path/to/tree.js')
/ ... /
`
Asserts
$3
`javascript
tree('foo').is('foo') // passes
tree(1).is('1') // fails
tree(1).is(2) // fails
`
$3
`javascript
tree('foo').is('foo') // passes
tree(1).is('1') // passes
tree(1).is(2) // fails
`
$3
`javascript
tree('foo').ok() // passes
tree(0).ok() // fails
tree(null).ok() // fails
`
$3
`javascript
tree('str').type('string') // passes
tree(function(){}).type('function') // passes
tree(1).type('string') // fails
tree([]).type('array') // yep, this passes
`
$3
`javascript
tree().pass() // passes
`
$3
`javascript
tree().fail() // fails
`
$3
`javascript
var Fn1 = function(){throw new Error()}
var Fn2 = function(){}
tree(Fn1).throws() // passes
tree(Fn2).throws() // fails
`
$3
`javascript
tree([1,2]).deepEql([1,2]) // passes
tree({a:1,b:[22,33]}).deepEql({a:1,b:[22,33]}) // passes
tree({a:1,b:[22,33]}).deepEql({a:1,b:[22,34]}) // fails
`
Negation
!
You can use .not. on any assert to negate their result.`javascript
tree('123').not.is(123) // passes
tree(function(){}).not.throws() // passes
tree('123').not.like(123) // fails
`
Branching
Organize your asserts into a nice tree`javascript
tree.branch('Name these', function(tree) {
tree.branch('whatever', function(tree) {
/ ... /
})
tree.branch('you', function(tree) {
tree.branch('want!', function(tree) {
/ ... /
})
/ ... /
})
/ ... /
})
`
Async handling
$3
`javascript
tree.branch('this branch passes', function(tree){
tree.done(0)
})
tree.branch('this passes too', function(tree){
tree(true).ok()
tree.done(1)
})
tree.branch('this fails', function(tree){
tree(true).ok()
tree(true).ok()
tree.done(1)
})
// If you want to be more explicit you can also use tree.expect(\d)
// to say how many asserts you expect to run within the current branch
tree.branch('more explicit expect', function(tree){
tree.expect(1)
tree(true).ok()
tree.done()
})
tree.done(0)
`
$3
`javascript
tree.branch(function(tree) {
// executes 1st
setTimeout(function() {
// executes 3rd
tree.done(0)
}, 100)
// executes 2nd
})
tree.branch(function(tree) {
// executes 4th
setTimeout(function() {
// executes 6th
tree.done(0)
}, 100)
// executes 5th
})
// starts execution
tree.done(0)
`
$3
`javascript
tree.heritable.config({parallel:true})
tree.branch(function(tree) {
// executes 1st
setTimeout(function() {
// executes 5th
tree.done(0)
}, 100)
// executes 2nd
})
tree.branch(function(tree) {
// executes 3rd
setTimeout(function() {
// executes 6th
tree.done(0)
}, 200)
// executes 4th
})
// starts execution
tree.done(0)
`
$3
`javascript
tree.heritable.config({parallel:true})
tree.branch('waiter', function(tree) {
tree.waitForDone()
// executes 2nd
setTimeout(function() {
// executes 4th
tree.done(0)
}, 100)
// executes 3rd
})
tree.branch('rusher', function(tree) {
tree.fireNextToo()
// executes 5th
setTimeout(function() {
// executes 8th
tree.done(0)
}, 100)
// executes 6th
})
tree.branch('whatever', function(tree) {
// executes 7th
tree.done(0)
})
// executesn 1st
tree.done(0)
`
$3
Each branch has exaclty 1000 milliseconds by default to signal their finish with tree.done(). Should they time out they are considered failing. Default timeout value can be changed with tree.cfg('timeout', value)`javascript
tree.branch("I'm in time :)", function(tree) {
tree.waitForDone()
setTimeout(function() {
tree.done(0)
}, 600)
})
tree.branch('I time out :(', function(tree) {
setTimeout(function() {
tree.done(0)
}, 1200)
})
tree.branch("I take very long to run but it's normal.", function(tree) {
tree.config({timeout:3000})
setTimeout(function() {
tree.done(0)
}, 2600)
})
// executes 1st
tree.done(0)
``Copyright (c) 2011-2012 Nagy Milán "Wizek" <123.wizek@gmail.com>
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.