jQuery Style BDD

I have been warming up to the jQuery style of using method chaining. Then I thought: why are most unit test frameworks class based? There's no reason why we can't do it in the jQuery style...

Something like this:

$.describe('Bowling')
	.beforeEach(function(){
		this.bowling = new Bowling();
	})
	.should('score 0 for gutter game', function(){
		for (var i = 0; i < 20; i++)
			this.bowling.hit(i);
		this.bowling.score.shouldEqual(0);
	})
	.should('accumulate score', function(){
		this.bowling.hit(20);
		this.bowling.hit(10);
		this.bowling.score.shouldEqual(30);
	});

I am liking this syntax. The full bowling example is here. I guess I'll call this jquery.bdd. I just started using git/github btw. This is one of my first projects on it. Fork me. Fork me please.

Update: jquery.bdd has been replaced by another project of mine called describe - which is agnostic to Javascript framework and could be used with server-side Javascript environments like node.js. Other Javascript BDD testing frameworks include:

  1. jasmine from Pivotal Labs
  2. jspec from Visionmedia
  3. expresso from Visionmedia
  4. ntest from technoweenie
blog comments powered by Disqus