Wednesday, August 30th, 2006

Script.aculo.us Behaviour Driven Development Testing

Category: Prototype, Testing

<>p>Thomas Fuchs has added some new features to the script.aculo.us test library that borrow from Behaviour Driven Development.

javascript
< view plain text >
  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.

Related Content:

Posted by Dion Almaer at 12:31 pm
4 Comments

++++-
4 rating from 28 votes

4 Comments »

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:

RESPEC!

Comment by Aslak Hellesøy — August 31, 2006

[...] http://ajaxian.com/archives/scriptaculous-behaviour-driven-development-testing [...]

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

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

‘function(){‘+

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.