Introduction
Why?
I got fed up with QUnit which I was using to test the client side of one of my projects. It proved to be very unreliable when it came to async handling. I looked around for alternatives and to my surprise, I couldn't find anything more satisfying than what I was already using. Then came the idea: What if I'd write my own Unit Testing framework for JavaScript?
How?
- I should be able to trust it -- it needs to operate in a stable and reliable manner.
- It should have all the benefits of the frameworks I've already tried, with some addition I've always missed.
- It should look gorgeous, as I'll be looking at it a whole lot of times.
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.
What?
Tree.js, the Javascript Unit testing framework. (Some say it's the best one around.)
- 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:
Try it out online now!
Current highlights
✓
(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!
Get in touch
For questions, bug reports, feature requests and love letters choose an option most suitable for your liking:
- Google Group / Maining list
- GitHub: @Wizek
- IRC: on Freenode usually in ##javascript and #Node.js under the handle
Wizek
- Email: 123.wizek@gmail.com
Quick Start Guide
Download the latest release from here. This is all the markup you are going to need (if you use good old script tags):
<!-- jQuery won't be a dependency for long -->
When you run this, of course, it's gonna fail, because 1 === 2
is false.
Let's grow a branch! (html markup is the same, only writing js part)
treetree
Let's do that 2 more times.
treetreetree
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.
Reference guide
Three (3) loading modes supported!
Browser: Traditional
<!-- jQuery won't be a dependency for long -->
Browser: AMD
Node.js: require (WIP)
var tree = /* ... */
Asserts
a === b
Strict (triple) equal // passes // fails // fails
a == b
Loose (double) equal // passes // passes // fails
!! a
Truthy // passes // fails // fails
typeof a === b
+ some magic
Type type'string' // passestype'function' // passestype'string' // failstype'array' // yep, this passes
Always passing assert - Doesn't take arguments.
// passes
Always failing assert - Doesn't take arguments.
// fails
Check for exception
var {throw }var {} // passes // fails
Deep equal - compare two objects and their properties recursively
// passes // passes // fails
!
Negation You can use .not.
on any assert to negate their result.
not // passesnot // passesnot // fails
Branching
Organize your asserts into a nice tree
tree
Async handling
Assert count
treetreetree// 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 branchtreetree
Serial execution by default
treetree// starts executiontree
Set parallel execution
treeheritabletreetree// starts executiontree
Switch between parallel/serial on the fly with .waitForDone() and .fireNextToo()
treeheritabletreetreetree// executesn 1sttree
Timeout handling
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)
treetreetree// executes 1sttree
tl;dr
We are building the best JavaScript unit testing framework. Wanna join? Or, you can just use it too...
License
(The MIT License)
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.