Skip to content

Commit

Permalink
Added example test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 18, 2010
1 parent 0fbaef7 commit fd99ab2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 53 additions & 0 deletions examples/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

/**
* Module dependencies.
*/

var should = require('../');

function test(name, fn){
try {
fn();
} catch (err) {
console.log(' \x1b[31m%s', name);
console.log(' %s\x1b[0m', err.stack);
return;
}
console.log(' √ \x1b[32m%s\x1b[0m', name);
}

function Point(x, y) {
this.x = x;
this.y = y;
this.sub = function(other){
return new Point(
this.x - other.x
, this.y - other.y);
}
}

console.log();

test('new Point(x, y)', function(){
var point = new Point(50, 100);
point.should.be.an.instanceof(Point);
point.should.have.property('x', 50);
point.should.have.property('y', 100);
});

test('Point#sub()', function(){
var a = new Point(50, 100)
, b = new Point(20, 50);
a.sub(b).should.be.an.instanceof(Point);
a.sub(b).should.not.equal(a);
a.sub(b).should.not.equal(b);
a.sub(b).should.have.property('x', 30);
a.sub(b).should.have.property('y', 50);
});

test('Point#add()', function(){
var point = new Point(50, 100);
point.should.respondTo('add');
});

console.log();
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

module.exports = require('./lib');
module.exports = require('./lib/should');

0 comments on commit fd99ab2

Please sign in to comment.