Wednesday, August 30th, 2006 Behaviour Driven Development Testing

Category: Prototype, Testing

Thomas Fuchs has added some new features to the test library that borrow from Behaviour Driven Development.


  1. Test.context("BDD-style testing",{
  2.   'should automatically add extensions to strings': function(){
  3.     'a'.shouldEqual('a');
  4.     'a'.shouldNotEqual('b');
  5.     'a'.shouldNotBeNull();
  6.     'a'.shouldBeA(String);
  7.     'a'.shouldNotBeA(Number);
  8.   }
  9. });

Basically, you’re defining a context for which one or more specifications should be asserted. Note the easy readability, and the added value by using a string to describe the test/specification, giving you the advantage of having better documentation for your JavaScript libraries.

Of course, setup and teardown is also supported, as are all normal assert* methods.

This appears to have made it into the recent Prototype changes too.

Posted by Dion Almaer at 12:31 pm

4 rating from 28 votes


Comments feed TrackBack URI

Things like this make me happy. *HEART BDD*

Comment by Luke Redpath — August 30, 2006

Like me mate Ali G says:


Comment by Aslak Hellesøy — August 31, 2006

[…] […]

Pingback by 本日書籤 « penk - Keep on rockin’ in the free world — September 1, 2006

Currently(v1.7.1b3), BDD framework doesn’t support IE. But it can be easily fixed. Just edit line 530 from this:


to this:

‘x = function(){‘+

I hope it will help.

Comment by Alan Kang — July 11, 2007

Leave a comment

You must be logged in to post a comment.